如何确保Number列的值大于一?

时间:2019-03-29 21:32:57

标签: sql

我尝试添加“ HAVING Number> 1”,但是它不能正常工作,只能输出1行

SELECT 
    T.EmployeeID,
    COUNT(*) AS "Number" 
FROM (
    SELECT 
        Skill.Title,
        Skill.SkillID,
        EmployeeSkill.EmployeeID 
   FROM Skill 
   RIGHT JOIN EmployeeSkill ON EmployeeSkill.SkillID = Skill.SkillID
) T
GROUP BY T.EmployeeID

3 个答案:

答案 0 :(得分:0)

我相信,如果您使用“具有count(*)> 1”而不是“具有number> 1”,它应该可以工作

答案 1 :(得分:0)

如果您只想从查询中找到Number > 1
那么您需要在该语句中添加一个HAVING子句:

HAVING COUNT(*) > 1

答案 2 :(得分:0)

我怀疑您正在寻找至少具有两种技能的员工。如果是这样,那似乎是对表EmployeeSkill的简单汇总查询,例如:

SELECT EmployeeID, COUNT(*)
FROM EmployeeSkill 
GROUP BY EmployeeID
HAVING COUNT(*) > 1