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
;
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?