I was viewing a question on stackoverflow and came across the following query. I was wondering what the GROUP BY 1
was for.
SELECT
date(orderdate),
COUNT(id) AS num_orders
FROM orders
GROUP BY 1
ORDER BY orderdate DESC
I know this query will generate a list of orders per day ordered from high to low. I would just like to understand the GROUP BY
In short
- What is
GROUP BY 1
- Why wouldn't I use
GROUP BY orderdate
?
I mean either I should use column name or column position. Which method is preferable and why?