select waybillno, count(*) from waybillinfo where zonecode='中山公园' and optype='异常派件'
and count(waybillno) >3
select waybillno, count(*) from waybillinfo where zonecode='中山公园' and optype='异常派件'
order by waybillno having count(*) > 3
select waybillno, count(*) from waybillinfo where zonecode='中山公园' and optype='异常派件'
having count(*) > 3
select waybillno from waybillinfo where zonecode='中山公园' and optype='异常派件'
group by waybillno having count(*) > 3
having只能对group by的结果进行操作
having只用来在group by之后,having不可单独用,必须和group by用
2.拿着where指定的约束条件,去文件/表中取出一条条记录
3.将取出的一条条记录进行分组group by,如果没有group by,则整体作为一组
select waybillno ,count(*) from waybillinfo where zonecode='中山公园' and optype='异常派件' group by waybillno having count(*) > 3 不应该是这样子吗我看sum函数是这样子
SELECT waybillno FROM waybillinfo WHERE zonecode = '中山公园' AND optype = '异常派件' GROUP BY waybillno HAVING COUNT(*) > 3;
筛选条件(WHERE子句):
zonecode = '中山公园':限定网点为中山公园。
optype = '异常派件':限定操作类型为异常派件。
分组(GROUP BY子句):
GROUP BY waybillno:按快件单号分组,以便统计每个快件的异常派送次数。
聚合过滤(HAVING子句):
HAVING COUNT(*) > 3:筛选出异常派送次数超过3次的快件(使用COUNT(*)统计每组记录数)。