比如,统计客服 在 2018-08-21 与  2018-08-22 之间被投诉的次数,需要group by两次才可以

一次按照user_id去分组,一次按照时间去分组

date_format(q.oper_time,'%m-%d-%Y')
SELECT COUNT(s.user_id) AS compNum, user_id,date_format(q.oper_time,'%m-%d-%Y')
        FROM qc_complaint_schedule q
        LEFT JOIN sy_user_info s ON s.user_id = q.operator_id
      where
             progress_type = 1 and oper_time>="2018-08-21 16:00:40"  and oper_time < "2018-08-22 00:00:00"
        GROUP BY s.user_id, date_format(q.oper_time,'%m-%d-%Y')

分组后的效果为:会按照每个人每天被投诉的次数 去进行分组

按天数进行统计的时候要注意

如果没有加上按照时间分组的话,查询效果是这样:

按天数进行统计的时候要注意

id为2的人的两天的投诉记录就被合并为了一天 

相关文章:

  • 2021-12-27
  • 2021-12-27
  • 2021-11-27
  • 2022-12-23
  • 2021-08-18
  • 2021-06-14
  • 2021-10-01
  • 2021-12-04
猜你喜欢
  • 2021-09-11
  • 2021-08-03
  • 2022-12-23
  • 2022-12-23
  • 2021-09-20
  • 2022-12-23
  • 2022-02-21
相关资源
相似解决方案