Skip to content
Advertisement

PostgreSQL error when removing orders placed closer than 2 minutes apart SQL Error [42803]: ERROR: aggregate functions are not allowed in WHERE

I am getting the following error when removing orders placed closer than 2 minutes apart, but I cannot use HAVING as there isn’t a GROUP BY in the sub query.

Am I approaching this correctly and should I GROUP something to make this work?

SQL Error [42803]: ERROR: aggregate functions are not allowed in WHERE

Advertisement

Answer

OK, I rewrote your query using CTEs, and fixed the aggregation. Here it is:

I can’t really run this query and test it for real, but you get the idea.

By the way, sub and s2 can be combined into a single CTE. The same can be said about subx and s2x.

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