What is wrong with the following SQL statement? (Try to figure it out without running it):

SELECT order_num, COUNT() AS items
FROM OrderItems
GROUP BY items
ORDER BY items, order_num;

GROUP BY items is incorrect. GROUP BY must be an actual column, not the one being used to perform the aggregate calculations. GROUP BY order_num would be allowed.

Comment on this FAQ