Skip to content

SQL groups inside groups

I have transaction data like this example:

I need to group by user and sort by the number of transactions in general, but within that group of users also make groups by price ordering by the amount of transactions at that price. I need this result:

UPDATE

It is in a MySQL 5.5 database. I need to make the query for fluent in Laravel but having it in SQL is a great advance.

Thanks in advance.

Advertisement

Answer

fiddle

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