Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL COUNT Query w/ three other sub-queries

Status
Not open for further replies.
Aug 1, 2006
1
US
I've got a table with the following fields:
---------------------------------
StudyID Year Month Modality

A222 2006 jan CT
B342 2006 jan CT
D545 2006 mar MR
S676 2006 apr CT
S897 2006 apr MR
R321 2006 apr MR
Q908 2005 mar MR
T456 2005 mar MR
T324 2005 feb CT
S100 2005 feb MR
---------------------------------

I want to return this Query:
-----------------------------------------
Year Month Modality StudyCount

2006 jan CT 2
2006 mar MR 1
2006 apr CT 1
2006 apr MR 2

2005 mar MR 2
2005 feb CT 1
2005 feb MR 1
-----------------------------------------

It's a COUNT Query and I want to count how many studies are there sorted by each Modality, Month, and Year.
All I've got is:

SELECT COUNT(StudyID) AS StudyCount
FROM TableName;

Should I use VBA to do this or could it all be done using one SQL based Query in Access ?

Thanks in advance.
 
A starting point:
SELECT [Year], [Month], Modality, Count(*) AS StudyCount
FROM TableName
GROUP BY [Year], [Month], Modality

I quite don't understand why you need TWO fields for storing a SINGLE DateTime value.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Code:
Select [Year], [Month], Modality, Count(*) As TheCount

From myTable

Group By [Year], [Month], Modality
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top