hive的语句执行顺序是group by ..、select ..、order by
order by是对前面查询到的结果进行排序,两者连用的语法顺序即 select ..、group by ..、order by
注意事项有两点:
1、order by的字段必须是在group by中,或者是聚合函数
1、select file1,file2 from tableName group by file1,file2 order by file1;2、select file1, count(*) as num from tableName group by file1 order by count(*)
2、写法上,order by后的字段顺序,必须与group by后的字段顺序一致,两者都是从左到右执行,group by A,B,C,执行的时候会先对A列分组,再在每个组里对B进行分组,以此类推
select file1,file2,file3 from tableName group by file1,file2,file3 order by file1,file2;