MAX(ROW_NUMBER)
does not work in teradata
. But in cases where where it is required to implement the same scenario, how to achieve that?
Suppose my base table looks like this--
Month Prev_Sport Curr_Sport
JAN REST CRICKET
JAN CRICKET RUGBY
FEB REST SKATING
FEB SKATING RAFTING
MAR REST RACING
MAR RACING GLIDING
The output table should be like--
Month First_Sport Last_Sport
JAN CRICKET RUGBY
FEB SKATING RAFTING
MAR RACING GLIDING
Here we can get the desired Last_Sport
column in output if we create rownumber
on main table and fetch the data based on the max(rownumber)
. But the same does not work in teradata
.
Is there any alternative solution for that?
No existing DBMS allows a MAX(ROW_NUMBER).
You didn't show how the ROW_NUMBER is calculated, but when you want the MAX of it you can simply reverse the ORDER and then
QUALIFY ROW_NUMBER() OVER (PARTITION BY ... ORDER BY .... DESC) = 1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.