Skip to content
Advertisement

How to count the number of orders and the number of returns from same order id?

I’m trying to derive a table as CustomerID, OrderCount and ReturnCount from a table with columns as CustomerID, OrderID, ReturnFlag

I’ve tried the following code that gives me 2 distinct tables but I want the results in a single output table.

Source Table –

Expected output table –

Advertisement

Answer

Use a case expression to do conditional aggregation:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement