Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
ishitab
Starting Member
1 Post |
Posted - 2014-08-22 : 09:59:32
|
Hi, I am new to SQL. I have below data in one of my table:Calls|Status4|-612|-111|01|-10Desired Output required : Total_calls|Zero|Non-Zero18|1|17Please help. |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-08-22 : 10:16:36
|
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(...) ...etcFROM myTable |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2014-08-22 : 11:52:39
|
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 |
|
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-08-22 : 12:57:55
|
Hey Peter! You should have let him give it a try! |
|
|
|
|
|