IT Log

SELECT 본문

SQL/Hive(HiveQL)

SELECT

newly0513 2021. 3. 24. 16:30
728x90
반응형
[WITH CommonTableExpression (, CommonTableExpression)*] 
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 [offset,] rows]

 

ALL | DISTINCT

ALL : 모든 행을 출력

DISTINCT : 중복 제거한 모든 행을 출력

COL1    COL2
1       2
1       3
1       4

-- COL1에 대한 중복을 제거한 뒤 출력(1만 출력)
SELECT COL1 FROM hivetest

-- COL1과 COL2에 대한 중복을 제거한 뒤 출력(중복이 없으니 전부 출력됨)
SELECT COL1, COL2 FROM hivetest

 

table_reference

table_reference:
    table_factor
  | join_table
  
join_table:
    table_reference [INNER] JOIN table_factor [join_condition]
  | table_reference {LEFT|RIGHT|FULL} [OUTER] JOIN table_reference join_condition
  | table_reference LEFT SEMI JOIN table_reference join_condition
  | table_reference CROSS JOIN table_reference [join_condition]
 
table_factor:
    tbl_name [alias]
  | table_subquery alias
  | ( table_references )
 
join_condition:
    ON expression

 

table_subquery

  • HIVE 서브쿼리는 FROM절만 지원
  • Table Alias를 지정
  • IN / NOT IN 서브 쿼리는 단일 열만 선택
  • EXISTS / NOT EXISTS는 하나 이상의 상관 술어 포함

 

 

LIMIT

offset : 시작할 행을 지정 (기본값은 0)

rows : 출력할 행 수를 지정

-- 4번째 행부터 3개의 행을 출력 (4~6번째 출력)
SELECT * FROM hivetest LIMIT 3, 3;
728x90
반응형

'SQL > Hive(HiveQL)' 카테고리의 다른 글

CREATE/DROP/TRUNCATE TABLE  (0) 2021.03.24
CREATE/DROP/ALTER DATABASE  (0) 2021.03.24
ALTER TABLE/COLUMN & PARTITION  (0) 2021.03.24
Show  (0) 2021.02.09
Comments