我正在尝试收集一组MI来计算“事件”的数量'一天。因为这是MI我还需要列出没有任何事件的日子。上市。我的查询如下:
SELECT
event_timestamp,
COUNT(*)
FROM
table1
GROUP BY
event_timestamp
ORDER BY
event_timestamp
;
无论如何,可以修改此查询以显示所有日期(不仅仅是带有事件的日期),如果可能的话显示' 0'对于没有事件的日期?
答案 0 :(得分:4)
Teradata中有一个简单的日历,具有公共访问权限:
SELECT
c.calendar_date,
COUNT(event_timestamp) -- need to count a column from the inner table
FROM sys_calendar.CALENDAR AS c
LEFT JOIN
table1
ON c.calendar_date = event_timestamp -- assuming event_timestamp is a DATE, otherwise it's CAST(event_timestamp AS DATE)
WHERE c.calendar_date BETWEEN your-starting-date AND your-ending-date
GROUP BY
c.calendar_date
ORDER BY
c.calendar_date
;