1、查询group by having 中having不起作用,及解决
直接上SQL:
需求是根据acontainer_number,aparentid分组后,数据大于1的数据,下面的语句竟不起作用。
//记录以前这样写是可以,不知为何现在不可以了
select acontainer_number,aparentid
from xxxxx_table
where acontainer_number is not null
group by acontainer_number,aparentid
having count(*) > 1
解决方法:
只能再套一个子查询:
select acontainer_number,aparentid from (
select acontainer_number,aparentid
from xxxxx_table
where acontainer_number is not null
group by acontainer_number,aparentid
) ag group by aparentid
having count(*) > 1
后面有时间再研究吧