Skip to content
Advertisement

SQL sum grouped by field with all rows

I have this table:

I want this result:

I tried this:

But get the error that subquery returns different number of rows. How can I do it?

I want all the rows of sale_lines table selecting all fields and adding the sum(price) grouped by sale_id.

Advertisement

Answer

You can use window function :

If you want sub-query then you need to correlate them :

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