hql与sql的不同点

606 阅读1分钟

草稿-持续更新中

1. hive 中的 group by与order by

  • 在 Group by 子句中,Select 查询的列,必须满足以下两种情况:

    • 需要是 Group by 中的列,不支持直接查询非 Group by 的列。如果查询非 Group by 的列,则用情况二。
    • 是用聚合函数(比如 sum、count 、Max、Min、avg、collect_list、collect_set等)加工过的列。这一点和 MySQL 有所区别
  • hive中select的非聚合字段和group by字段必须一一匹配,是因为hive执行顺序是group在前,select在后(MySQL相反)。

  • order by与group by连用时:order by的字段必须是在group by中,或者为聚合函数;写法上,order by后的字段顺序,必须与group by后的字段顺序一致,两者都是从左到右执行。

原理:t.zoukankan.com/foolangirl-…

2. hive 嵌套查询时子查询需要别名

Hive SQL语法报错 及相应解决方法

hive sql中的“坑”

hive嵌套查询时子查询需要别名,不然会报错:

Error while compiling statement: FAILED: ParseException line 3:6 cannot recognize input near '(' 'select' 'A' in joinSource

3. 数据类型

  • hql中存在String类型,而sql只有varchar,且varchar必须指定大小。