CREATE VIEW

description

  1. 该语句用于创建一个逻辑视图
  2. 语法:
  3. CREATE VIEW [IF NOT EXISTS]
  4. [db_name.]view_name
  5. (column1[ COMMENT "col comment"][, column2, ...])
  6. AS query_stmt
  7. 说明:
  8. 1. 视图为逻辑视图,没有物理存储。所有在视图上的查询相当于在视图对应的子查询上进行。
  9. 2. query_stmt 为任意支持的 SQL

example

  1. 1. example_db 上创建视图 example_view
  2. CREATE VIEW example_db.example_view (k1, k2, k3, v1)
  3. AS
  4. SELECT c1 as k1, k2, k3, SUM(v1) FROM example_table
  5. WHERE k1 = 20160112 GROUP BY k1,k2,k3;
  6. 2. 创建一个包含 comment view
  7. CREATE VIEW example_db.example_view
  8. (
  9. k1 COMMENT "first key",
  10. k2 COMMENT "second key",
  11. k3 COMMENT "third key",
  12. v1 COMMENT "first value"
  13. )
  14. COMMENT "my first view"
  15. AS
  16. SELECT c1 as k1, k2, k3, SUM(v1) FROM example_table
  17. WHERE k1 = 20160112 GROUP BY k1,k2,k3;

keyword

  1. CREATE,VIEW