Wednesday, March 7, 2012

GROUP BY day (with a datestamp column)

I have a table as follows

id date_time
-- -------
1 2003-10-04 12:09:00
2 2003-10-04 13:09:00
3 2003-10-05 12:09:00
4 2003-10-05 14:09:00
5 2003-10-06 14:09:00

I want to have a count of each record in the same day. So my results should be

total date
-------
2 2003-10-04
2 2003-10-05
1 2003-10-06

Any help?You could try:


SELECT
count(*) AS total,
CONVERT(char(8), date_time,112) AS date
FROM
myTable
GROUP BY
CONVERT(char(8), date_time,112)

Terri

No comments:

Post a Comment