Select

[TOC]

Select Syntax

[WITH CommonTableExpression (, CommonTableExpression)*]    (Note: Only available starting with Hive 0.13.0)
SELECT [ALL | DISTINCT] select_expr, select_expr, ...
  FROM table_reference
  [WHERE where_condition]
  [GROUP BY col_list]
  [ORDER BY col_list]
  [CLUSTER BY col_list
    | [DISTRIBUTE BY col_list] [SORT BY col_list]
  ]
 [LIMIT number]
  • select 可以是union query的一部分,也可以是另一个query的subquery

  • table_reference 标识了query的输入。 可以是一个严格意义上的table, 一个view,一个join查询或者一个子查询

  • table 名和column 名大小写相同

  • 简单查询 SELECT * FROM t1 从hive0.13.0开始,from可选(如: select 1+1)

  • 获取当前的数据库

      SELECT     current_database()
  • 当指定数据库之后,可以通过指定在table名前家database名 或者使用 USE 来查询不同的database

      use database_name;
      select query_specifications;
      use default;

WHERE Clause

where是boolean表达式,支持数值操作和UDF

ALL and DISTINCT Clauses

All 和 DISTINCT 选项用于指明重复的数据是否需要返回。 默认为ALL,

Partition Based Queries

table创建分区之后,查询可以在每个分区上运行, 而且只会扫描查询中涉及到的分区。

也可以在join的on表达式中使用分区

HAVING Clause

从hive0.7.0中开始支持hiving

与之等同的子查询如下

LIMIT Clause

决定查询返回的条数, 返回的条数是随机的。

  • top K 查询

REGEX Column Specification

在hive0.13.0之前的版本,默认支持column上的正在表达式, 在0.13.0之后,需要配置资源文件 hive.support.quoted.identifiers 为 none

Last updated

Was this helpful?