Skip to content
Advertisement

SQLite: How to avoid using two CTE when using CASE statement?

I have a table trx with following schema:

where id is the transaction id and p_id the id of the person doing it.

I need to query trx so I get a table that allows me to plot an histogram of frequencies of transactions, that means, I want to know how many p_id did only 1 transaction, how many did 2, and so on. I have to aggregate 11 and more transactions in a +10 bin:

I know that I need the CASE statement for the +10 thing, and I approached the task using two CTE:

I would like to know if there is a way to have a more direct approach than my actual (working) query.

Here is the SQLFiddle

Advertisement

Answer

You can use CASE in GROUP BY

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