sql - Counting NULL values in a case statement -


i have following sql query:

select jobs.id,  jobs.title, sum(case when jobresponses.result = 'true' 1 else 0 end) true, sum(case when jobresponses.result = 'false' 1 else 0 end) false, sum(case when jobresponses.result != 'true' , jobresponses.result != 'false' 1 else 0 end) incomplete jobresponses  join jobs on jobresponses.jobid = jobs.id jobs.id = 1 group jobs.id, jobs.title 

the third case expressions in practice counting values result of null, safe (between '', undefined , null) wanted have catch "other" type field. however, issue null values aren't being counted. see this sql fiddle.

use is null:

select jobs.id,  jobs.title, sum(case when jobresponses.result = 'true' 1 else 0 end) true, sum(case when jobresponses.result = 'false' 1 else 0 end) false, sum(case when jobresponses.result null                      -- detect null               or jobresponses.result not in ('true', 'false')  -- other values    1 else 0 end) incomplete jobresponses  join jobs on jobresponses.jobid = jobs.id jobs.id = 1 group jobs.id, jobs.title; 

rextester demo


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -