我一直在研究一项在excel中很简单的项目,而在teradata中我做不到。
在excel中,我使用以下公式=COUNTIFS($A$2:$A$30000,"<="&E2,$B$2:$B$30000,">="&E2)
对最近7天的活动项目进行计数。
这很容易,因为最近7天在单独的列中,并且不确定如何在Teradata中获得相同的结果?
dt已经过去了7天:
SELECT calendar_date AS dt
FROM sys_calendar.CALENDAR
WHERE calendar_date between (CURRENT_DATE - 7) and (CURRENT_DATE)
ORDER BY dt
T1保存所有数据:
CREATE TABLE T1
(
ID INT ,
Open_Date DATE format 'YYYY-MM-DD',
Close_Date DATE format 'YYYY-MM-DD')
insert into T1 values (1, '2018-12-17', '2018-12-18')
insert into T1 values (2, '2018-12-18', '2018-12-18')
insert into T1 values (3, '2018-12-18', '2018-12-18')
insert into T1 values (4, '2018-12-19', '2018-12-20')
insert into T1 values (5, '2018-12-19', '2018-12-21')
insert into T1 values (6, '2018-12-20', '2018-12-22')
insert into T1 values (7, '2018-12-20', '2018-12-22')
insert into T1 values (8, '2018-12-21', '2018-12-25')
insert into T1 values (9, '2018-12-22', '2018-12-26')
insert into T1 values (10, '2018-12-23', '2018-12-27')