MySQL显示值为IS NULL或IN(2,3)的行

时间:2016-07-20 10:41:12

标签: mysql

我正在尝试查询他们的球队在15,9,25,26,23,18,12和null。问题是查询没有检索到NULL记录。

我尝试使用OR team IS NULL查询为我提供了所有其他状态。

SELECT e.*,
FROM enquiries e
WHERE e.timestamp BETWEEN '1293840000' AND '1469055599'
  AND e.status IN(1) AND e.team IN(15, 9, 25, 26, 23, 18, 12, NULL)
ORDER BY e.timestamp ASC

请帮助

1 个答案:

答案 0 :(得分:1)

将OR条件放在括号中

SELECT e.*,
FROM enquiries e
WHERE e.timestamp BETWEEN '1293840000' AND '1469055599'
AND e.status IN(1) AND ( e.team IN (15, 9, 25, 26, 23, 18, 12) OR e.team IS NULL)
ORDER BY e.timestamp ASC