Skip to content
Advertisement

LEFT JOIN not showing days with zero COUNT

I am trying to retrieve data from the last X days, counting the new rows per day. I need to get also the days that have COUNT = 0.

My query right now is:

It is returning the following:

As you can see, there are days that are not being displayed by the query.

Advertisement

Answer

You should be able to simplify it like so:

A couple notes:

  • the calendar_date field in the sys_calendar.calendar view is DATE, no need to cast it
  • Teradata lets you reference aliased columns without having to do an outer SELECT
  • replaced COUNT(*) with COUNT(a.TIMESTAMP_T) for a more accurate count (thanks jarlh)
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement