
January 31st, 2013, 04:07 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 2
Time spent in forums: 35 m 16 sec
Reputation Power: 0
|
|
|
Count with max(date)
I have a historical data table where most of the data is captured once a month. The sites can change but most is the same.
I need to pull the count from only the most current month for a report and was using something basic:
Select count(site_id) as lastmonthcount
from sitehistory
where capture_date = '09/30/2012'
Now I need to make it so I don't have to maintain the report every month and the capture date can pull the most recent counts.
I have
Select count(site_id) as lastmonthcount, capture_date
from sitehistory
group by capture_date
having capture_date =max(capture_date)
order by capture_date desc
I get the following results
lastmonthcount capture_date
29918 09/30/2012
39048 08/31/2012
36768 07/31/2012
38689 06/30/2012
What I really want is just the top record.
Can someone help me? I know I am close just
missing something
Thanks
Karen
|