I have a PostgreSQL table that looks like:
artists | songs
===================
artist1 | song a
artist1 | song b
artist2 | song c
and I want to make a select statement that gives me for every artist the number of tracks and the difference between the number of his tracks and the number of the artist with the most tracks
so in this case
artist | number songs | difference
====================================
artist1 | 2 | 0
artist2 | 1 | 1
The problem I'm having is that I am using count(songs) for the number of songs and also max(count(songs)) (needed to calculate the difference) in the same result And using both gives me problems with nested aggregated functions.