16.6. CREATE VIEW
CREATE [ OR REPLACE ] VIEW view_name AS query
Create a new view of a SELECT query. The view is a logical table that can be referenced by future queries. Views do not contain any data. Instead, the query stored by the view is executed everytime the view is referenced by another query.
OR REPLACE clause causes the view to be replaced if it
already exists rather than raising an error.
Create a simple view
test over the
CREATE VIEW test AS SELECT orderkey, orderstatus, totalprice / 2 AS half FROM orders
Create a view
orders_by_date that summarizes
CREATE VIEW orders_by_date AS SELECT orderdate, sum(totalprice) AS price FROM orders GROUP BY orderdate
Create a view that replaces an existing view:
CREATE OR REPLACE VIEW test AS SELECT orderkey, orderstatus, totalprice / 4 AS quarter FROM orders