SQL question

How can I change this query to give me 2 counts - the number of records where "updated = 0" and the number of records where "updated = 1"

select count(*) from case_note
where updated = 1
LVL 1
HLRosenbergerAsked:
Who is Participating?
 
sdstuberConnect With a Mentor Commented:
or, do conditional counting

select  count(case where updated = 0 then 1 end),
count(case where updated = 1 then 1 end)
from case_note
0
 
sdstuberCommented:
try union...

elect 1, count(*) from case_note
where updated = 1
union all
select 0,count(*) from case_note
where updated = 0
0
 
thombeckConnect With a Mentor Commented:
Hi,

select 
Sum(case when updated=1 THEN 1 ELSE 0 END),
Sum(case when updated=0 THEN 1 ELSE 0 END)
from case_note

Open in new window

0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
awking00Connect With a Mentor Commented:
select updated, count(*)
from case_note
where updated in (1,2)
group by updated;
0
 
santhimurthydCommented:
Try this, but feel as your queries not clear as whetehr you need two result set else one result with condition for updated.

select 'Number of records where updated = ' + updated  + ' is ' + count(*)
from case_note group by updated;
0
 
HLRosenbergerAuthor Commented:
Thanks,.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.