我想知道是否可以在sql查询中使用<> 1, 2, 3, ...etc
表示一组数字(ID)。以下是我的询问:
SELECT DISTINCT dName
FROM department
INNER JOIN employee ON employee.id_Dept = department.id_Dept
INNER JOIN emp_proj ON employee.id_Emp = emp_proj.id_Emp
INNER JOIN project ON project.id_proj = emp_proj.id_proj
WHERE project.id_Proj <> 1, 2, 3, 4, 5, 6;
答案 0 :(得分:0)
您可以使用NOT IN
。
SELECT DISTINCT dName
FROM department
INNER JOIN employee ON employee.id_Dept = department.id_Dept
INNER JOIN emp_proj ON employee.id_Emp = emp_proj.id_Emp
INNER JOIN project ON project.id_proj = emp_proj.id_proj AND project.id_Proj NOT IN {1, 2, 3, 4, 5, 6};
答案 1 :(得分:0)
使用&#39;&#39;运营商解决上述问题..
以下是示例代码
select * from department where dept_id in (1,2,3);
以上查询将仅生成dept_id为1,2或3的记录
答案 2 :(得分:0)
改变这个
WHERE project.id_Proj <> 1, 2, 3, 4, 5, 6;
到这个
WHERE project.id_Proj NOT IN ( 1, 2, 3, 4, 5, 6);