Use a subquery?

jmersing

Well-known Member
Joined
Apr 14, 2004
Messages
887
I would like to see a total for each month of the year in this same format, would that be a subquery? I'm not sure how to setup the syntax.

I want to see how many canid's are in each month as the months go by


SELECT Attrit.division, Count(Attrit.canid) AS CountOfcanid

FROM Attrit

where Attrit.[Hire Date]<=#2/1/2007#

GROUP BY Attrit.division

;
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I don't think you need a subquery for this, seems like you just need to include month(Attrit.[Hire Date]) into your query.

hth,
Giacomo
 
Upvote 0
Code:
SELECT Attrit.division,month(Attrit.[Hire Date]) as month, Count(Attrit.canid) AS CountOfcanid 

FROM Attrit 

where Attrit.[Hire Date]<=#2/1/2007# 

GROUP BY Attrit.division, month(Attrit.[Hire Date]) 

;

hth,
Giacomo
 
Upvote 0
I was actually looking for a result that would populate individual columns as months, like the result of what these three queries would produce if their columns were combined.

SELECT Attrit.division, Attrit.workgroup, Count(Attrit.canid) AS Jan

FROM Attrit

WHERE Attrit.[Hire Date] <= #2/1/2007#

GROUP BY Attrit.division, Attrit.workgroup

WITH OWNERACCESS OPTION;



SELECT Attrit.division, Attrit.workgroup, Count(Attrit.canid) AS Jan

FROM Attrit

WHERE Attrit.[Hire Date] <= #3/1/2007#

GROUP BY Attrit.division, Attrit.workgroup

WITH OWNERACCESS OPTION;



SELECT Attrit.division, Attrit.workgroup, Count(Attrit.canid) AS Jan

FROM Attrit

WHERE Attrit.[Hire Date] <= #4/1/2007#

GROUP BY Attrit.division, Attrit.workgroup

WITH OWNERACCESS OPTION;
 
Upvote 0
I believe you need a crosstab query. Take a look at the help for crosstab's and post back if you're still having trouble.

hth,
Giacomo
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,700
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top