我正在使用MySQL
,
我想获取每天每小时交付的平均物品数量
例如:
一月份我们有5个星期一,平均=(2 + 0 + 0 + 1 + 0)/ 5 =在星期一的1:00-2:00小时期间交付的0.6件物品
我使用了以下编码:
SELECT
Hour(CST_data.dateandtime_CST) as Hours_Order,
Concat(Hour(CST_data.dateandtime_CST), ':00-', Hour(CST_data.dateandtime_CST) + 1, ':00') as Hours_in_CST,
Sum(DayofWeek(CST_data.dateandtime_CST)=1) as Sun,
Sum(DayofWeek(CST_data.dateandtime_CST)=2) as Mon,
Sum(DayofWeek(CST_data.dateandtime_CST)=3) as Tue,
Sum(DayofWeek(CST_data.dateandtime_CST)=4) as Wed,
Sum(DayofWeek(CST_data.dateandtime_CST)=5) as Thu,
Sum(DayofWeek(CST_data.dateandtime_CST)=6) as Fri,
Sum(DayofWeek(CST_data.dateandtime_CST)=7) as Sat,
Count(CST_data.dateandtime_CST) as Total_Count,
count(distinct(day(CST_data.dateandtime_CST))) as No_of_Days,
Count(CST_data.dateandtime_CST) / count( distinct(day(CST_data.dateandtime_CST))) as Avg_Count
FROM
(Select Timestampadd(Hour,-5,updated_at) as dateandtime_CST from
case_state_transitions
where
To_state = 'delivered'
and date(dateandtime) between '2017-01-01' and '2017-01-31'
) as CST_data
group by Hours_in_CST, Hours_Order
order by Hours_Order;
你能否帮我找一下这个编码本身的星期一(星期日到星期六)的数量。