select dr_drvname, count(sh_drvnum)
from driver join shift on dr_drvnum = sh_drvnum
where count(sh_drvnum) not like '1'
group by dr_drvname;
此代码不起作用。我知道某处需要涉及子查询,但我无法弄清楚什么和在哪里。谢谢。
got it solved here's the answer
select dr_drvname, count(sh_drvnum)
from driver join shift on dr_drvnum = sh_drvnum
group by dr_drvname
having count(sh_drvnum) > 1;
或者,在加入之前预先聚合计数:
select dr_drvname,
shift_count
from driver inner join (
select sh_drvnum,
count(*) shift_count
from shift
group by sh_drvnum
having count(*) > 1) on (dr_drvname = sh_drvname)