[thelist] CF & SQL: Selecting unique months from date column
Tab Alleman
Tab.Alleman at MetroGuide.com
Thu Jul 17 15:49:43 CDT 2003
Minh Lee Goon wrote:
> Thank you so much for the input. I didn't realize that SQL had a
> Month() function. That will come in handy.
>
> Now that I've implemented that, I wonder if I could extend my
> question. I'd like to also get the year with each date instead of
> just the number of the month. In short, I'd like to select one record
> for each month. Is there a simple way of doing that?
In fact, considering the first solution, it's just what you'd expect:
> SELECT Month(DateColumn), Year(DateColumn)
> FROM TableName
> GROUP BY Year(DateColumn), Month(DateColumn)
(the order of the GROUP BY clause is important)
More information about the thelist
mailing list