?
Solved

SQL question

Posted on 2013-01-09
6
Medium Priority
?
193 Views
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
0
Comment
Question by:HLRosenberger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 38760385
try union...

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

Accepted Solution

by:
sdstuber earned 668 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
0
 
LVL 2

Assisted Solution

by:thombeck
thombeck earned 668 total points
ID: 38760396
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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 32

Assisted Solution

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

Expert Comment

by:santhimurthyd
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;
0
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 38763931
Thanks,.
0

Featured Post

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how the fundamental information of how to create a table.

801 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