各时间段统计订单缴费信息.txt 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. -- 按小时统计订单缴费信息
  2. select
  3. time_id,
  4. ifnull(amount,0) as amount
  5. from
  6. luo_time_data b1
  7. left join
  8. (select
  9. case when hour(c.pay_time) is null then 0 else hour(c.pay_time) end pay_time,
  10. case when sum(amount) is null then 0 else round(sum(amount)/100,2) end as amount
  11. FROM
  12. luo_park_baseinfo t
  13. left join
  14. (select a.park_id,a.pay_time,b.amount
  15. from luo_parking_chargerecord a
  16. inner join luo_parking_chargerecord_subject b
  17. on a.order_no=b.order_no) c
  18. ON t.park_id = c.park_id
  19. where t.area_id = '411102'
  20. AND t.keys_areas = '商圈'
  21. AND t.street_name LIKE '%人民%'
  22. group by 1) c1
  23. on b1.time_id=c1.pay_time
  24. -- 按日统计订单缴费信息
  25. select
  26. case when day(c.pay_time) is null then 1 else day(c.pay_time) end pay_time,
  27. case when sum(amount) is null then 0 else round(sum(amount)/100,2) end as amount
  28. FROM
  29. luo_park_baseinfo t
  30. left join
  31. (select a.park_id,a.pay_time,b.amount
  32. from luo_parking_chargerecord a
  33. inner join luo_parking_chargerecord_subject b
  34. on a.order_no=b.order_no) c
  35. ON t.park_id = c.park_id
  36. where t.area_id = '411102'
  37. AND t.keys_areas = '商圈'
  38. AND t.street_name LIKE '%人民%'
  39. group by 1
  40. -- 按周统计订单缴费信息
  41. select
  42. case when WEEKDAY(c.pay_time)+1 is null then 1 else WEEKDAY(c.pay_time)+1 end pay_time,
  43. case when sum(amount) is null then 0 else round(sum(amount)/100,2) end as amount
  44. FROM
  45. luo_park_baseinfo t
  46. left join
  47. (select a.park_id,a.pay_time,b.amount
  48. from luo_parking_chargerecord a
  49. inner join luo_parking_chargerecord_subject b
  50. on a.order_no=b.order_no) c
  51. ON t.park_id = c.park_id
  52. where t.area_id = '411102'
  53. AND t.keys_areas = '商圈'
  54. AND t.street_name LIKE '%人民%'
  55. group by 1
  56. -- 按年统计订单缴费信息
  57. select
  58. case when YEAR(c.pay_time) is null then 2024 else YEAR(c.pay_time) end pay_time,
  59. case when sum(amount) is null then 0 else round(sum(amount)/100,2) end as amount
  60. FROM
  61. luo_park_baseinfo t
  62. left join
  63. (select a.park_id,a.pay_time,b.amount
  64. from luo_parking_chargerecord a
  65. inner join luo_parking_chargerecord_subject b
  66. on a.order_no=b.order_no) c
  67. ON t.park_id = c.park_id
  68. where t.area_id = '411102'
  69. AND t.keys_areas = '商圈'
  70. AND t.street_name LIKE '%人民%'
  71. group by 1