我有一个表格,其中包含字段student_number和已完成或未完成的已完成标记。
我正在寻找一个where子句,它允许我检查选择是否有3个学生编号,并检查他们是否已在完成的字段中完成,但所有必须匹配。
知道如何判断这个吗?
答案 0 :(得分:0)
可能你想要这样的东西:
where STUDENT.NUMBER in (34646, 57858, 48482) and COMPLETED = 'COMPLETED'
(基于你的评论)
答案 1 :(得分:0)
DROP TABLE T;
CREATE TABLE T (ID INT, COMPLETED VARCHAR(20))
INSERT INTO T VALUES
(34646, 'COMPLETD'),(57858,'COMPLETeD'),(48482,'COMPLETED')
SELECT case when s.sta > 0 then 'NotAllCompleted'
else 'AllCompleted'
end
FROM
(
SELECT SUM(CASE WHEN COMPLETED <> 'COMPLETED' AND ID IN(34646,57858,48482) THEN 1 ELSE 0 END) sta
FROM T
) S
---------------
NotAllCompleted
(1 rows affected)
truncate table t
INSERT INTO T VALUES
(34646, 'COMPLETeD'),(57858,'COMPLETeD'),(48482,'COMPLETED')
SELECT case when s.sta > 0 then 'NotAllCompleted'
else 'AllCompleted'
end
FROM
(
SELECT SUM(CASE WHEN COMPLETED <> 'COMPLETED' AND ID IN(34646,57858,48482) THEN 1 ELSE 0 END) sta
FROM T
) S
---------------
AllCompleted
(1 rows affected)