Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2011
    Posts
    3

    Unanswered: Counting rows grouped by date

    I need to retrieve counts of table rows based on dates, so if my rows look like :

    Date | Name
    ----------------
    Date1 | Name1
    Date1 | Name2
    Date1 | Name3
    Date2 | Name4
    Date2 | Name5

    I would need this result

    Date | Count
    ----------------
    Date1 | 3
    Date2 | 2

    A further complication is that the dates have a time element which would need to be ignored thereby making only the date part significant.
    So if an item had a date of '2010-04-14 16:04:02' it would need to be part of a count that also included '2010-04-14 14:33:10'
    Can anyone assist?

    Thanks in anticipation

    Paul

  2. #2
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Code:
    SELECT cast(your_date_column as DATE), count(*)
    FROM your_table
    GROUP BY cast(your_date_column as DATE)

  3. #3
    Join Date
    Jan 2011
    Posts
    3
    Shammat, that works perfectly.

    Many thanks

    Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •