利用视图简化复杂的联结
create view productcustomers as
select cust_name, cust_contact,prod_id
from customers, orders, orderitems
where customers.cust_id = orders.cust_id
and orderitems.order_num =orders.order_num;
select cust_name,cust_contact
from productcustomers
where prod_id = 'TNT2';
用视图重新格式化检索出的数据
create view vendorlocations as
select concat (rtrim(vend_name), ' (', rtrim(vend_country),')') as vend_title
from vendors
order by vend_name;
select *
from vendorlocations;
通过视图过滤数据
create view customeremaillists as
select cust_id,cust_name,cust_email
from customers
where cust_email is not null;
select *
from customeremaillists;
使用视图与计算字段
create view orderitemsexpand as
select prod_id, quantity, item_price, quantity*item_price as expanded_price
from orderitems;
select *
from orderitemsexpand
where order_num = 20005;