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

Creating Group ID from SUM Limit - response (6) by saraider99

$
0
0

Is this the query you mean? I did the whole thing over so that I wouldnt have to do an insert and then an update. This still gives me some weird results what am I missing?

WITH PROD_CTE (PROD_NAME,QTY_SOLD) AS 
(
 SELECT 
  PROD_NAME
 , COUNT(DISTINCT PROD_ID) AS QTY_SOLD
 FROM all_prods
 GROUP BY 1
)
SELECT 
 PROD_NAME
, QTY_SOLD
, CUMLTV_SUM
, TTL
, (((RUNNING_SUM / TTL ) * 100  ) / 10) AS BUCKET
FROM (
SELECT
  PROD_NAME
, QTY_SOLD
, SUM(QTY_SOLD) OVER (ORDER BY QTY_SOLD ROWS UNBOUNDED PRECEDING) AS RUNNING_SUM
, TTL
FROM PROD_CTE 
JOIN (
 SELECT SUM(QTY_SOLD) TTL 
 FROM PROD_CTE 
 )sm ON 1=1
)v
;

 


Viewing all articles
Browse latest Browse all 14773

Trending Articles



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