Skip to content
Advertisement

Using group by with order in postgresql

Query:

It yields this:

What I need is to show those "fightEventId"s that have more than 2 CONFIRMED fights. Currently all records are ordered in the right way, so the result I expect is:

How do I do this? Every time I try, I get errors or the order is broken.

As for the DBMS used in the project, it’s PostgreSQL but I wrote MySQL cos I’m pretty sure there’re solutions that work with both.

P.S.

This query comes from the ORM I’m using, so please don’t be confused with those trues and falses. 🙂

Advertisement

Answer

You would just use aggregation and having:

In your query:

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