Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. select * from (SELECT
  2. LOJA,
  3. PDV,
  4. COUNT(CUPOM) AS TOTAL_CUPONS,
  5. SUM(MEDIDA) AS TOTAL_ITENS_VENDIDOS,
  6. SUM(VALOR) AS VALOR_TOTAL_VENDAS,
  7. HORA_FINAL
  8. FROM(
  9. SELECT
  10. sale_item.start_time,
  11. sale_item.store_key AS LOJA,
  12. sale_item.pos_number AS PDV,
  13. sale_item.ticket_number AS CUPOM,
  14. (CASE
  15. WHEN
  16. MINUTE(sale_item.start_time) >= '30'
  17. THEN concat(HOUR(sale_item.start_time), ':' ,'30',':00')
  18. ELSE concat(HOUR(sale_item.start_time), ':' ,'00',':00')
  19. END) HORA_FINAL,
  20. plu_id AS COD_PROD,
  21. replace(sale_item.quantity,'.',',') AS QUANT,
  22. sale_item.scanned AS SCAN,
  23. ( CASE
  24. WHEN plu.unit_key = '1' THEN
  25. sale_item.quantity
  26. ELSE 1 END) AS MEDIDA,
  27. sale_item.amount AS VALOR,
  28. user.alternate_id AS COD_OPERADOR,
  29. agent.name AS NOME_OPERADOR
  30. FROM sale_item, sale ,plu ,user,agent
  31. WHERE
  32. sale_item.pos_number > 0
  33. and sale_item.start_time between @dataini AND @datafin
  34. and sale_item.plu_id = plu.id
  35. and sale.store_key = sale_item.store_key
  36. and sale.pos_number = sale_item.pos_number
  37. and sale.start_time = sale_item.start_time
  38. and sale.ticket_number = sale_item.ticket_number
  39. and user.agent_key = sale.cashier_key
  40. and agent.agent_key = user.agent_key)
  41. Vendas
  42. GROUP BY LOJA,PDV,HORA_FINAL) as a1,
  43. (SELECT
  44. LOJA,
  45. PDV,
  46. HORA_FINAL,
  47. COUNT(*) as scan
  48. FROM(
  49. SELECT
  50. sale_item.start_time,
  51. sale_item.store_key AS LOJA,
  52. sale_item.pos_number AS PDV,
  53. sale_item.ticket_number AS CUPOM,
  54. (CASE
  55. WHEN
  56. MINUTE(sale_item.start_time) >= '30'
  57. THEN concat(HOUR(sale_item.start_time), ':' ,'30',':00')
  58. ELSE concat(HOUR(sale_item.start_time), ':' ,'00',':00')
  59. END) HORA_FINAL,
  60. plu_id AS COD_PROD,
  61. replace(sale_item.quantity,'.',',') AS QUANT,
  62. sale_item.scanned AS SCAN,
  63. ( CASE
  64. WHEN plu.unit_key = '1' THEN
  65. sale_item.quantity
  66. ELSE 1 END) AS MEDIDA,
  67. sale_item.amount AS VALOR,
  68. user.alternate_id AS COD_OPERADOR,
  69. agent.name AS NOME_OPERADOR
  70. FROM sale_item, sale ,plu ,user,agent
  71. WHERE
  72. sale_item.pos_number > 0
  73. and sale_item.start_time between @dataini AND @datafin
  74. and sale_item.plu_id = plu.id
  75. and sale.store_key = sale_item.store_key
  76. and sale.pos_number = sale_item.pos_number
  77. and sale.start_time = sale_item.start_time
  78. and sale.ticket_number = sale_item.ticket_number
  79. and user.agent_key = sale.cashier_key
  80. and agent.agent_key = user.agent_key and sale_item.scanned = '1')
  81. Vendas
  82. GROUP BY LOJA,PDV,HORA_FINAL) as a2
  83.  
  84. 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