[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

SQL question

Posted on 2013-01-09
6
Medium Priority
?
194 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
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

656 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