SQLite NOT NULL

时间:2014-03-05 13:56:47

标签: sql sqlite

如果(stage1_choice,stage2_choice或stage3_choice)value = null中的任何一个,如何排除该行?

enter image description here

我试过了:

SELECT  r.breakout_id ,
        r.case_id ,
        r.stage_id ,
        r.chart_id ,
        s.stage1_choice ,
        s.stage2_choice ,
        s.stage3_choice
FROM    Results AS r ,
        Submissions AS s
WHERE   r.breakout_id = '1'
        AND s.breakout_id = '1'
        AND r.case_id = s.case_id
        AND stage_id < 4
        AND s.stage1_choice NOT NULL
        AND s.stage2_choice NOT NULL
        AND s.stage3_choice NOT NULL    

但它仍会返回其中一列中包含null的行。

2 个答案:

答案 0 :(得分:2)

not null的正确语法不同,它是IS NOT NULL

AND s.stage1_choice IS NOT NULL 
AND s.stage2_choice IS NOT NULL 
AND s.stage3_choice IS NOT NULL

来自文档

  
      
  • 要测试NULL,请使用IS NULL和IS NOT NULL运算符
  •   

了解详情here

答案 1 :(得分:1)

SELECT r.breakout_id, r.case_id, r.stage_id, r.chart_id, s.stage1_choice, s.stage2_choice, s.stage3_choice
FROM Results as r, Submissions as s 
WHERE r.breakout_id = '1' AND s.breakout_id = '1' AND r.case_id = s.case_id AND stage_id < 4 AND s.stage1_choice NOT NULL AND s.stage2_choice IS NOT NULL AND s.stage3_choice IS NOT NULL

SELECT r.breakout_id, r.case_id, r.stage_id, r.chart_id, s.stage1_choice,   s.stage2_choice, s.stage3_choice
FROM Results as r, Submissions as s 
WHERE r.breakout_id = '1' AND s.breakout_id = '1' AND r.case_id = s.case_id AND stage_id < 4 AND s.stage1_choice != '' AND s.stage2_choice != '' AND s.stage3_choice != ''