SQL question

Posted on 2013-01-09
Last Modified: 2013-01-10
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
Question by:HLRosenberger
LVL 73

Expert Comment

ID: 38760385
try union...

elect 1, count(*) from case_note
where updated = 1
union all
select 0,count(*) from case_note
where updated = 0
LVL 73

Accepted Solution

sdstuber earned 167 total points
ID: 38760391
or, do conditional counting

select  count(case where updated = 0 then 1 end),
count(case where updated = 1 then 1 end)
from case_note

Assisted Solution

thombeck earned 167 total points
ID: 38760396

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

LVL 32

Assisted Solution

awking00 earned 166 total points
ID: 38760847
select updated, count(*)
from case_note
where updated in (1,2)
group by updated;
LVL 15

Expert Comment

ID: 38762778
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;

Author Closing Comment

ID: 38763931

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now