BookmarkSubscribeRSS Feed
karankhayani97
Calcite | Level 5

I have made a CTE that shows the orderdate sum of the ordered quantity, and its respective cumulative frequency. I have to keep this line "JOIN cte c2 ON c1.orderdate<=c2.orderdate" in this form only and get the correct results. Please tell me what changes are to be made in the code to get the correct result. The code is done in Postgres. Below is the output which I want.

CODE

NOTE: No changes have to be made in this line "JOIN cte c2 ON c1.orderdate<=c2.orderdate"

WITH cte
AS(
SELECT o.orderdate, SUM(od.quantity) AS "totalsum" FROM orders o
JOIN orderdetails od ON o.orderid=od.orderid
GROUP BY o.orderdate
)
SELECT c1.orderdate, c1.totalsum, SUM(c2.totalsum) FROM cte c1
JOIN cte c2 ON c1.orderdate<=c2.orderdate
GROUP BY c1.orderdate, c1.totalsum
ORDER BY c1.orderdate;

 

karankhayani97_0-1612797527554.png

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Tips for filtering data sources in SAS Visual Analytics

See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 0 replies
  • 416 views
  • 0 likes
  • 1 in conversation