SQL求助聚合计算:一段日期特定时段每位售货员苹果的总销量。

我想计算一段时间内(比如整月),每位售货员,12:00到15:00,苹果的销量。
但以下语法只能计算:每天,每位售货员,12:00到15:00,苹果的销量。

select  
date, job_id,
count(distinct case when substr(order_time,12,2) between 12 and 15 then ord_id end) as apple_order
from
A
where
date >='${startdate}' and date<='${enddate}' and type='apple'
group by
job_id,date

#sql##MySQL##学习路径#
全部评论
select   month(date) as mon ........ group by job_id,mon 这样不知道能不能行😂
1 回复
分享
发布于 2021-05-30 15:32
把现在的当成子查询时间改成一个月的区间,再来select一次,count(*)只group by id😂
1 回复
分享
发布于 2021-07-14 08:59
联想
校招火热招聘中
官网直投
或者with cube 然后把不要的汇总排除掉
点赞 回复
分享
发布于 2021-07-14 09:00

相关推荐

2 4 评论
分享
牛客网
牛客企业服务