2014-03-27 106 views
0

为什么说这种说法适用于自己的,但是当它是一个子查询的一部分,它说无效使用组功能为什么在子查询中这个MySQL语句不工作?

select count(cid) 
    from qualification q 
     inner join faculty f 
      on q.fid=f.fid 
      where fname='Berry' 
group by 
     f.fid; 

的我会怎样修改,以适合子查询?

整个查询 -

select fid, fname from faculty 
where fid in 
(select fid from qualification where count(cid)= 
    (select count(cid) from qualification q inner join faculty f on 
    q.fid=f.fid where fname='Berry' group by f.fid)); 

逻辑:列表FNAME和所有教职员工谁可以教所有贝里教授能教

+3

你能显示整个查询吗? – 2014-03-27 07:59:20

+0

聚合函数过滤器必须与'HAVING'而非'WHERE'一起使用 –

回答

1

对我来说,问题的课程FID使用count()WHERE

where count(cid)= 
(select count(cid) from qualification q inner join faculty f on 
q.fid=f.fid where fname='Berry' group by f.fid) 

您可以尝试将其更改为像这样处理

HAVING count(cid)= 
(select count(cid) from qualification q inner join faculty f on 
q.fid=f.fid where fname='Berry' group by f.fid) 

但我不明白逻辑。如果你解释更多,我们会建议更好的解决方案

相关问题