SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL query for grouping and join
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ishitab
Starting Member

India
1 Posts

Posted - 08/22/2014 :  09:59:32  Show Profile  Reply with Quote

Hi,
I am new to SQL. I have below data in one of my table:

Calls|Status
4|-6
12|-11
1|0
1|-10

Desired Output required :
Total_calls|Zero|Non-Zero
18|1|17


Please help.

gbritton
Aged Yak Warrior

806 Posts

Posted - 08/22/2014 :  10:16:36  Show Profile  Reply with Quote
What have you tried so far? (I think you should give it a try first!)

Hint: use the SUM() function like this:


SELECT SUM(...), SUM(...) ...etc
FROM myTable
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30242 Posts

Posted - 08/22/2014 :  11:52:39  Show Profile  Visit SwePeso's Homepage  Reply with Quote
SELECT SUM(Calls) AS [Total_calls], SUM(CASE WHEN Status = 0 THEN 1 ELSE 0 END) AS Zero, SUM(CASE WHEN Status = 0 THEN 0 ELSE 1 END) AS [Non-zero]
FROM dbo.Table1


Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

gbritton
Aged Yak Warrior

806 Posts

Posted - 08/22/2014 :  12:57:55  Show Profile  Reply with Quote
Hey Peter! You should have let him give it a try!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000