What do numbers mean in SQL ORDER/GROUP BY statements? -
i don't understand sql sub-query , doubts it:
- what purpose of numbers after "group by" , "order by" keyword i.e. group 1,2,3 or order 1,2
subquery:
select a.dep_month, a.dep_day_of_week, avg(a.flight_distance) average_distance ( select dep_month, dep_day_of_week, dep_date, sum(distance) flight_distance flights group 1,2,3 ) group 1,2 order 1,2;
thanks in advance :)
well, order 1, 2
means order 1st , 2nd fields in select,
select a.dep_month, a.dep_day_of_week, ... order 1,2;
is equal to
select a.dep_month, a.dep_day_of_week, ... order a.dep_month, a.dep_day_of_week;
the syntax can convenient if have long , complex expression in field:
select bla-bla-bla-...-bla-bla, ... order 1 -- no copy + paste of "bla-bla-bla-...-bla-bla"
a better approach, however, put alias
select bla-bla-bla-...-bla-bla myexpression, ... order myexpression -- more readable 1
Comments
Post a Comment