Skip to content
Advertisement

Grouping with order in complex data

I have data like this

Grouping based on Name, valuta and type. (type2 always have a unique value based on name) and sum the price when have the same group condition, the last step is to order based the highest price followed by same group condition.

And after process (Group & Order), the output should be like this:

I tried use cte because pipeline process design seems clear to me but the result is wrong.

Advertisement

Answer

You can do it with MAX() window function in the ORDER BY clause:

See the demo.
Results:

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