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

Can some one provide the solution for the below scenario? - response (50) by teradata_chela2

$
0
0

Hi saikandimalla   
I am not sure if insert statements given by you are right  .
 
Below query will work for the results that you want .
 
SEL
cust_id,
src_id ,
branch,
month_end_date,
MAX(MTD) ,
MAX(YTD)
FROM
(
SEL
cust_id,
src_id ,
branch,
ADD_MONTHS( month_end_date -EXTRACT( DAY FROM month_end_date ) , 1 )month_end_date ,
SUM(amt) OVER ( PARTITION BY cust_id ,src_id, branch ,EXTRACT( MONTH FROM month_end_date ) ORDER BY month_end_date ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) MTD,
SUM(amt) OVER ( PARTITION BY cust_id ,src_id, branch ORDER BY month_end_date ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) YTD
FROM sales
)a
GROUP BY 1,2,3,4
 
Let me know if doesnt work .


Viewing all articles
Browse latest Browse all 14773

Trending Articles



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