利用视图简化复杂的联结
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;
本文介绍如何利用视图简化复杂的多表联接操作,包括创建productcustomers视图、重新格式化数据、过滤email列表和计算字段扩展。此外,还展示了创建vendorlocations视图和使用视图进行数据筛选的方法。
4885

被折叠的 条评论
为什么被折叠?



