显示驱动程序和涉及的转移次数超过1

时间:2012-12-02 19:10:07

标签: sql oracle

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;

此代码不起作用。我知道某个地方需要有一个子查询,但我无法弄清楚在哪里和哪里。感谢。

2 个答案:

答案 0 :(得分:0)

得到它解决了这里的答案

select dr_drvname, count(sh_drvnum)
from driver join shift on dr_drvnum = sh_drvnum
group by dr_drvname
having count(sh_drvnum) > 1;

答案 1 :(得分:0)

替代方案,在加入之前预先聚合计数:

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)