Aggregate and count dates in SQL
Many may have a table in a database, where they also have one or more date fields. If you ever have the wish to count the number of occurrences of each day, read on for info on how to write SQL for just this. Sometimes I wish SQL had a function to do just the thing I want it to do. Most of the times it doesn't, so I need to write something much more complex from the existing functions. My first experimentation by reading SQL reference info produced this; (SQL Server flavour) select DISTINCT( DATEADD(dd,DATEDIFF(dd,MIN(MYDATE),MYDATE), DATEADD(mm,DATEDIFF(mm,MIN(MYDATE),MYDATE), DATEADD(yyyy,DATEDIFF(yyyy,MIN(MYDATE),MYDATE), MIN(MYDATE) )))) AS MYDAY, MYDAT...