Skip to content
Advertisement

I am trying to use SQL to count the number of rows for each date in my database

My database is something like this:

I only need the counts of the dates like this:

I’ve tried …

… but the date format is not my friend. Any ideas would be appreciated.

Advertisement

Answer

In most databases, you can remove the date component by converting to a date and using group by:

However, various databases also have other methods to do the conversion, such as:

  • date(date) in MySQL.
  • trunc(date) in Oracle.
  • date_trunc('day', date) in Postgres.
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement