In this SQL query,
SELECT
flights.distance AS flights_distance,
COUNT(*) AS flights_count
FROM `cloud-training-demos.looker_flights.flights` AS flights
GROUP BY
1
ORDER BY
2 DESC
what is meant by GROUP BY 1? Does 1 refer to flight_distance field?
Solved! Go to Solution.
what is meant by GROUP BY 1? Does 1 refer to flight_distance field?
Yes.
In many SQL dialects, you can `GROUP BY` (and `ORDER BY`) the position of the field as it appears in the `SELECT` clause. This is a convenient short-hand notation that helps when you need to group-by expressions that are fairly long and cumbersome to copy from `SELECT` to the `GROUP BY` clause of the query.
what is meant by GROUP BY 1? Does 1 refer to flight_distance field?
Yes.
In many SQL dialects, you can `GROUP BY` (and `ORDER BY`) the position of the field as it appears in the `SELECT` clause. This is a convenient short-hand notation that helps when you need to group-by expressions that are fairly long and cumbersome to copy from `SELECT` to the `GROUP BY` clause of the query.