SQL 选择具有计数的其他列
我们需要一个SQL查询来获取以下输出。
注意:表包含数百万记录。需要优化的查询
Select
E.EmpId, E.EmpName, E.Salary,
(select count(*) from Dept where EmpId=E.EmpId) as DeptCount
from Employee E
We need a SQL query to get the following output.
Note: Table contains millions of records. Need an optimized query
Select
E.EmpId, E.EmpName, E.Salary,
(select count(*) from Dept where EmpId=E.EmpId) as DeptCount
from Employee E
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
使用
使用
Count
汇总。Count
aggregate function would not be counted when the value isNULL
sqlfiddle
Try to use
OUTER JOIN
withCOUNT
aggregate.Count
aggregate function would not be counted when the value isNULL
sqlfiddle