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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Confusion on SQL

Author  Topic 

addytoe
Starting Member

5 Posts

Posted - 2009-06-24 : 23:59:43
I have a problem as I cannot seem to think logically on how I should go about doing this...

Let's say for example.. I have a table called PaymentRequest and inside of it, there are statuses like Pending, Processed and Rejected.

However, I want to display on the total of Pending, Processed and Rejected and at the same time, I want to display on status altogether but I have got no idea on how I should go about working this out...

This is the table I am seeking :

Status      Total

Pending      15
Processed    1
Rejected      2

I have got no idea on how I could combine these two statments together:

SELECT COUNT(status) as Total FROM PaymentRequest where status = 'Processed'

SELECT DISTINCT status as Status FROM PaymentRequest

I would appreciate any help from anyone out there... Thanks






khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-06-25 : 00:01:18
Are you using SQL 2005 ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

GhantaBro
Posting Yak Master

215 Posts

Posted - 2009-06-25 : 00:01:50
SELECT status, COUNT(1) as Total FROM PaymentRequest
group by status -- give u frequency of each status
Go to Top of Page

addytoe
Starting Member

5 Posts

Posted - 2009-06-25 : 00:13:06
Thanks alot GhantaBro !

I'm using SQL 2000 but I will be trying it on SQL 2005 (Is there a difference ? )

GhantaBro, do you mind explaining on the COUNT(1), I don't really quite understand...

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-06-25 : 05:43:10
Both Count(1) and count(*) are same

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-25 : 13:22:04
quote:
Originally posted by addytoe

Thanks alot GhantaBro !

I'm using SQL 2000 but I will be trying it on SQL 2005 (Is there a difference ? )

GhantaBro, do you mind explaining on the COUNT(1), I don't really quite understand...






SELECT Status,COUNT(*) as Total
FROM PaymentRequest
GROUP BY Status
WITH ROLLUP
Go to Top of Page
   

- Advertisement -