我是使用SQL Server和数据库的新手 - 这可能非常简单。
我正在尝试为JobTitle
和Count(*)
返回仅Count(*)
超过9的值的值。我还尝试测试了一些子查询但无法使其工作。
Use AdventureWorks2014;
Select
JobTitle, Count(*) as Number
From
HumanResources.Employee
Where
Number > 9
Group By
JobTitle;
答案 0 :(得分:3)
将逻辑从WHERE
子句移到HAVING
子句中:
Select JobTitle, COUNT(*) AS Number
FROM HumanResources.Employee
GROUP BY JobTitle
HAVING COUNT(*) > 9
ORDER BY COUNT(*); -- or ORDER BY Number