我不知道如何编写这个查询甚至如何解释它 - 基本上我试图让 WHERE 子句适用于多行。
我有一张这样的 table :
RuleID QuestionID AnswerID
=================================
1 1100 1105
1 1200 1205
1 1300 1305
2 1100 1105
2 1200 1206
2 1300 1305
我想知道如何获得所有具有特定问题/答案的唯一 RuleID。
例如,类似这样的事情,但显然这不会返回任何结果,因为它正在检查同一行上的每个 where 子句。
select DISTINCT RuleID FROM table
where (QuestionID=1100 and AnswerID=1105)
and (QuestionID=1200 and AnswerID=1205)
and (QuestionID=1300 and AnswerID=1305)
最佳答案
试试这个简单的改变
select DISTINCT RuleID FROM table
where (QuestionID=1100 and AnswerID=1105)
or (QuestionID=1200 and AnswerID=1205)
or (QuestionID=1300 and AnswerID=1305)
关于SQL - 使用适用于多行的 WHERE 进行选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6537081/