Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Teradata 查询如下所示:
Select a, b, MIN(Record_Start_Date) as MIN_Record_Start_Date, MAX(Record_End_Date) as MAX_Record_End_Date FROM tbl GROUP BY 1,2
现在我想添加第三个属性“状态”。问题是-我只想要“最后一个”状态-“Record_End_Date”值最高的行的值。
有人可以帮忙吗?
切换到 OLAP 函数而不是聚合:
SELECT a, b, MIN(Record_Start_Date) OVER (PARTITION BY a, b) AS MIN_Record_Start_Date, Record_End_Date AS MAX_Record_End_Date, Status FROM tbl QUALIFY ROW_NUMBER() OVER (PARTITION BY a,b ORDER BY Record_End_date DESC) = 1