Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

Get Most Current Date - response (1) by dnoeth

$
0
0

The easiest way is to add a RANK:

select ca8172.*
   ,ord.order_due_dt as ORD_DUE_DT
   ,ord.cust_reason_txt as RSN_TXT
   ,ord.order_reason_cd as ORD_RSN_CD
from ORDER_ACTION ord, ca8172_AcctCharge ca8172
where ord.acct= ca8172.acct
and ord.bypass_reason_cd = 'VS'
and ord.current_status_cd = 'DO'
and ord.order_reason_cd in ('VA','ML','DR')
qualify rank() over (order by ORD_DUE_DT desc) = 1

If you want to get the most current date for different groups, e.g. per ACCT simply add "PARTITION BY ACCT" before the ORDER BY
 
Dieter


Viewing all articles
Browse latest Browse all 14773

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>