2020-11-07
阅读量:
1858
mysql里where和having一块用应注意什么?
1、根据司机完单表求2017年7月1日-2017年7月31日,有过10天以上的完单并且总完单量在20单以上的司机id,司机姓名,司机完单天数、司机完单数
select driver_daily.driver_id,driver_name,count(distinct concat(d_year,d_month,d_day)) as 完单天数,count(distinct order_id) as 完单数
from driver_daily
where d_year=2017 and d_month=7
group by driver_daily.driver_id
having 完单数>20 and 完单天数>10;
2、根据司机信息表(driver_info)和司机汇总表(driver_collect)取出近2017.07.01-2017.07.31完单大于30单的司机姓名及电话
select driver_name,driver_phone
from driver_info
where driver_id in (select driver_id from driver_collect where d_year=2017 and d_month=7 group by driver_id having count(order_id)>30);






评论(1)

推荐帖子
1条评论
0条评论