Sql 当子查询返回多个列时,如何仅使用一个列?
假设我有一个子查询,比如Sql 当子查询返回多个列时,如何仅使用一个列?,sql,subquery,Sql,Subquery,假设我有一个子查询,比如 select deptNo, count(*) from employee group by deptNo 我想在我的主查询中使用justcount*,我该怎么做 例如:查询如select deptNo中的count*、按deptNo从员工组中的count*; 或者有什么办法可以替代呢 select avg(cnt) from ( select deptNo, count(*) as cnt from employee group by deptN
select deptNo, count(*)
from employee group by deptNo
我想在我的主查询中使用justcount*,我该怎么做
例如:查询如select deptNo中的count*、按deptNo从员工组中的count*;
或者有什么办法可以替代呢
select avg(cnt)
from (
select deptNo, count(*) as cnt
from employee group by deptNo) src
尝试在内部查询中为计数指定别名。我假设您在此处只需要列count1。我已将该列命名为count1只需在子查询中选择count*,只需删除deptNo列。除此之外:算在。。。看起来很奇怪。你确定你不想要having子句吗?你不能用IN子句。如果这就是你想要做的。我不能删除deptNo,因为我是按那个属性分组的,这只是一个例子。实际上,我想要在子查询中获得的所有计数*的平均值
select t.count1 from
(select deptNo,count(*) as count1 from employee group by deptNo) as t