Window functions with grouping and aggregation

As window functions are evaluated after grouping, it is possible to use aggregating functions as arguments for window functions, but not the other way around.

A code like the following is correct: sum(count(*)) OVER()

This will also work: sum(a) OVER(ORDER BY count(*))

However, the code, sum(count(*) OVER()), is wrong.

For example, to calculate the rank of the seller accounts by the number of advertisements they give, the following query can be used:

car_portal=> SELECT seller_account_id, dense_rank() OVER(ORDER BY count(*) DESC)
FROM car_portal_app.advertisement
GROUP BY seller_account_id;
seller_account_id | dense_rank
-------------------+------------
26 | 1
128 | 2
28 | 2
126 | 2
...
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset