SELECT ques_id,ans_desc
FROM answer
ORDER BY ans_desc
HAVING ans_desc=0
答案 0 :(得分:2)
使用ans_desc IS NULL
子句中的WHERE
谓词:
SELECT ques_id, ans_desc
FROM answer
WHERE ans_desc = 0 OR ans_desc IS NULL
ORDER BY ans_desc ;
这只会为您提供0
列中NULL
或ans_desc
值的广告。
仅WHERE ans_desc = 0
不会提供NULL
值。
答案 1 :(得分:0)
0
与NULL
不同,与空
SELECT ques_id,ans_desc
FROM answer
WHERE ISNULL(ans_desc) OR ans_desc = ''
ORDER BY ans_desc
答案 2 :(得分:0)
当您只需要选择具有NULL值的行时,我认为您甚至不需要'按ans_desc排序'。
您应该执行以下操作:
SELECT ques_id as `question`, ans_desc as `answer`
FROM answer
WHERE ans_desc is NULL;
此查询的优点是它不使用filesort。
请参阅您正在使用的查询的解释输出。
希望有所帮助。