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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Multiple Counts

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-09-09 : 09:14:47
Adrian Inman writes "Can you do multiple counts in an SQL Select statement?
I have two tables I join together - Images and ImageAreas by ImageID.

One count counts how many ImageAreas there are for each Image.
I would like a second count to count the number of ImageArea records meeting a certain criteria per Image."

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-09-09 : 09:27:59
Sure. Just select from two derived tables ....



Jay White
{0}
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-09-09 : 09:31:25
You can also try using the CASE expression:

SELECT ImageName, Count(*) AS ImageAreas,
Sum(CASE ImageFormat WHEN 'JPG' THEN 1 ELSE 0 END) AS JPEGs,
Sum(CASE ImageFormat WHEN 'GIF' THEN 1 ELSE 0 END) AS GIFs
FROM ImageTable
GROUP BY ImageName


Go to Top of Page
   

- Advertisement -