假设我有一个像
这样的子查询select deptNo, count(*)
from employee group by deptNo
我想在主查询中使用count(*),我该怎么做?
例如:count(*) in (select deptNo, count(*) from employee group by deptNo)
之类的查询;
或者做什么的替代方案?
答案 0 :(得分:0)
select avg(cnt)
from (
select deptNo, count(*) as cnt
from employee group by deptNo) src
答案 1 :(得分:0)
select t.count1 from
(select deptNo,count(*) as count1 from employee group by deptNo) as t
尝试在内部查询中使用别名来计算。我假设您只需要列count1。(我已将列命名为count1)