Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select * from (SELECT
- LOJA,
- PDV,
- COUNT(CUPOM) AS TOTAL_CUPONS,
- SUM(MEDIDA) AS TOTAL_ITENS_VENDIDOS,
- SUM(VALOR) AS VALOR_TOTAL_VENDAS,
- HORA_FINAL
- FROM(
- SELECT
- sale_item.start_time,
- sale_item.store_key AS LOJA,
- sale_item.pos_number AS PDV,
- sale_item.ticket_number AS CUPOM,
- (CASE
- WHEN
- MINUTE(sale_item.start_time) >= '30'
- THEN concat(HOUR(sale_item.start_time), ':' ,'30',':00')
- ELSE concat(HOUR(sale_item.start_time), ':' ,'00',':00')
- END) HORA_FINAL,
- plu_id AS COD_PROD,
- replace(sale_item.quantity,'.',',') AS QUANT,
- sale_item.scanned AS SCAN,
- ( CASE
- WHEN plu.unit_key = '1' THEN
- sale_item.quantity
- ELSE 1 END) AS MEDIDA,
- sale_item.amount AS VALOR,
- user.alternate_id AS COD_OPERADOR,
- agent.name AS NOME_OPERADOR
- FROM sale_item, sale ,plu ,user,agent
- WHERE
- sale_item.pos_number > 0
- and sale_item.start_time between @dataini AND @datafin
- and sale_item.plu_id = plu.id
- and sale.store_key = sale_item.store_key
- and sale.pos_number = sale_item.pos_number
- and sale.start_time = sale_item.start_time
- and sale.ticket_number = sale_item.ticket_number
- and user.agent_key = sale.cashier_key
- and agent.agent_key = user.agent_key)
- Vendas
- GROUP BY LOJA,PDV,HORA_FINAL) as a1,
- (SELECT
- LOJA,
- PDV,
- HORA_FINAL,
- COUNT(*) as scan
- FROM(
- SELECT
- sale_item.start_time,
- sale_item.store_key AS LOJA,
- sale_item.pos_number AS PDV,
- sale_item.ticket_number AS CUPOM,
- (CASE
- WHEN
- MINUTE(sale_item.start_time) >= '30'
- THEN concat(HOUR(sale_item.start_time), ':' ,'30',':00')
- ELSE concat(HOUR(sale_item.start_time), ':' ,'00',':00')
- END) HORA_FINAL,
- plu_id AS COD_PROD,
- replace(sale_item.quantity,'.',',') AS QUANT,
- sale_item.scanned AS SCAN,
- ( CASE
- WHEN plu.unit_key = '1' THEN
- sale_item.quantity
- ELSE 1 END) AS MEDIDA,
- sale_item.amount AS VALOR,
- user.alternate_id AS COD_OPERADOR,
- agent.name AS NOME_OPERADOR
- FROM sale_item, sale ,plu ,user,agent
- WHERE
- sale_item.pos_number > 0
- and sale_item.start_time between @dataini AND @datafin
- and sale_item.plu_id = plu.id
- and sale.store_key = sale_item.store_key
- and sale.pos_number = sale_item.pos_number
- and sale.start_time = sale_item.start_time
- and sale.ticket_number = sale_item.ticket_number
- and user.agent_key = sale.cashier_key
- and agent.agent_key = user.agent_key and sale_item.scanned = '1')
- Vendas
- GROUP BY LOJA,PDV,HORA_FINAL) as a2
- where a1.pdv = a2.pdv and a1.loja = a2.loja and a1.hora_final = a2.hora_final
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement