CREATE-VIEW

Name

CREATE VIEW

Description

This statement is used to create a logical view grammar:

  1. CREATE VIEW [IF NOT EXISTS]
  2. [db_name.]view_name
  3. (column1[ COMMENT "col comment"][, column2, ...])
  4. AS query_stmt

illustrate:

  • Views are logical views and have no physical storage. All queries on the view are equivalent to the sub-queries corresponding to the view.
  • query_stmt is any supported SQL

Example

  1. Create the view example_view on example_db

    1. CREATE VIEW example_db.example_view (k1, k2, k3, v1)
    2. AS
    3. SELECT c1 as k1, k2, k3, SUM(v1) FROM example_table
    4. WHERE k1 = 20160112 GROUP BY k1,k2,k3;
  2. Create a view with a comment

    1. CREATE VIEW example_db.example_view
    2. (
    3. k1 COMMENT "first key",
    4. k2 COMMENT "second key",
    5. k3 COMMENT "third key",
    6. v1 COMMENT "first value"
    7. )
    8. COMMENT "my first view"
    9. AS
    10. SELECT c1 as k1, k2, k3, SUM(v1) FROM example_table
    11. WHERE k1 = 20160112 GROUP BY k1,k2,k3;

Keywords

  1. CREATE, VIEW

Best Practice