Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Questionable statement about performance and memory consumption.
In postgres WITH is always optimization fence. PG always materialize it.
Here you basically told PG to make two temp tables out of payment table doing two scans (index or maybe full table ones as we don't have any idea if staff_id is indexed or not or anything about its cardinality and distribution).
Sorry, but with all things being equal this query does two scans instead of one while AGGREGATE WITH FILTER approach gets all aggregates in a single pass over the table (using index or not). Not knowing table statistics we cannot simply say what will be faster.
That's true, but anyone who's read LYAH should be familiar with monoids, especially 6-kyu Haskellers, the kata's difficulty level.