CREATE VIEW

Description

  1. This statement is used to create a logical view
  2. Grammar:
  3. CREATE VIEW [IF NOT EXISTS]
  4. [db_name.]view_name
  5. (column1[ COMMENT "col comment"][, column2, ...])
  6. AS query_stmt
  7. Explain:
  8. 1. Views are logical views without physical storage. All queries on views are equivalent to sub-queries corresponding to views.
  9. 2. query_stmt is arbitrarily supported SQL.

example

  1. 1. Create view example_view on example_db
  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. Create view with comment
  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