CREATEVIEW clients_balance AS SELECT i.client_id, name, SUM(invoice_total-payment_total) balance FROM invoices i JOIN clients c USING(client_id) GROUPBY i.client_id,name ORDERBY i.client_id;
删除视图
格式:DROP VIEW 【视图名】
1
DROPVIEW clients_balance
更改视图
格式:CREATE OR REPLACE VIEW 【视图名】 AS + 查询语句
1 2 3 4 5 6 7 8
CREATEOR REPLACE VIEW sales_by_clients AS-- 创建或更新sales_by_clients视图 SELECT c.client_id, c.name, SUM(invoice_total) total_sales FROM clients c JOIN invoices i USING(client_id) GROUPBY client_id, name