SELECT ModuleID
FROM tblActivity
Where (Day = 2 And Day = 3 )
在这里,我试图显示星期二(2)和星期三(3)的ModuleID。所有信息都存储在同一个表中。当我执行它时,它只显示模块ID作为列,而下面没有数据。
答案 0 :(得分:0)
你应该使用OR而不是AND。 您也可以使用IN,如下所示
SELECT ModuleID
FROM tblActivity
Where Day IN (2,3)
答案 1 :(得分:0)
where语句由ROW
评估,因此请考虑以下示例:
ModuleId Day
1 1
2 2
3 3
4 4
5 2
6 2
7 3
要参加这组数据的请求,ModuleId的结果为2,3,5,6和7
当数据库评估ROW
所处的条件时,所以当你说(Day = 2 And Day=3)
时,它会像这样测试每一行:
1 1 is day=2 - false AND is day=3 - false
2 2 is day=2 - TRUE AND is day=3 - FALSE | TRUE and FALSE = FALSE
3 3 is day=2 - false AND is day=3 - TRUE | FALSE and TRUE = FALSE
4 4 is day=2 - false AND is day=3 - false and so on for next lines
5 2 is day=2 - false AND is day=3 - false
6 2 is day=2 - false AND is day=3 - false
7 3 is day=2 - false AND is day=3 - false
这就是你必须使用OR
的原因select ModuleID
from tblActivity
where days = 2 or days = 3
将评估为
1 1 is day=2 - false OR is day=3 - false > FALSE
2 2 is day=2 - TRUE OR is day=3 - FALSE | TRUE OR FALSE = TRUE
3 3 is day=2 - false OR is day=3 - TRUE | FALSE OR TRUE = TRUE
4 4 is day=2 - false OR is day=3 - false and so on for next lines
5 2 is day=2 - false OR is day=3 - false
6 2 is day=2 - false OR is day=3 - false
7 3 is day=2 - false OR is day=3 - false
请在此处查看:http://sqlfiddle.com/#!9/a7c5b0/1
如评论中所述,您可以使用IN
运算符:
select ModuleID
from tblActivity
where days IN (2, 3)