一、知识
视图
视图的实质就是把 sql语句封装起来方便我们多次使用。有一些复杂的查询指令如果我们每次都手打,效率实在很低于是推出视图。以下代码,相当于我们把后面的sql指令抓取的数据单独储存起来建成视图(view),以便后续使用。
create view tyqsl2.ProductsCustomers AS
select cust_name,cust_contact,prod_id from tyqsl2.customers as c,
tyqsl2.orders as o ,tyqsl2.orderitems as item
where c.cust_id = o.cust_id and item.order_num = o.order_num
稍微复杂点的用法
构造视图,只是用稍微复杂点的sql语句/
create view tyqsl2.orderitemsexpended AS
SELECT order_num,order_item,prod_id,quantity,item_price,
quantity * item_price as totoal_price
FROM
tyqsl2.orderitems;
一、课后习题
create view tyqsl2.customersWithOrders as
select c.* from tyqsl2.customers as c
left join tyqsl2.orders as o
on c.cust_id=o.cust_id
2.