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
 Total of a count

Author  Topic 

Shelly1
Starting Member

25 Posts

Posted - 2009-05-06 : 11:33:02
Hi, i would like to know how to create a Total calculation of ID.

select count(ID) as emerg_count

Hope this makes sense, would be great if someone could help
many thanks
M

Mich

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2009-05-06 : 12:12:22
This amkes no sense. What calculation would you apply to id? Your current query will basically count the records in the table. Do you want to see how many records are in the table for each ID?
How many distinct IDs there are in the table?

Jim
Go to Top of Page

Shelly1
Starting Member

25 Posts

Posted - 2009-05-11 : 11:13:18
Hi Yes, i would like to Total the number of distinct IDS there are in the table
M

Mich
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-11 : 11:18:22
then it should be

select count(distinct ID) as emerg_count from yourtable
Go to Top of Page

Shelly1
Starting Member

25 Posts

Posted - 2009-05-11 : 11:27:00
Apologies i dont think i am making myself clear, i am trying to TOTAL the count of ID's.
e.g:

Emerg-Count PCT
10 AAA
12 BBB
15 CCC
16 CCD
17 EEF
Total 70




Mich
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-11 : 11:33:53
select SUM(Emerg-Count) from yourtable
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-11 : 11:37:01
and just in case Emerg-Count is derived use this

SELECT SUM([Emerg-Count])
FROM
(
SELECT COUNT(*) AS [Emerg-Count],PCT
FROM Table
GROUP BY PCT
)t
Go to Top of Page
   

- Advertisement -