《mysql必知必会》学习_第22章

第22章:使用视图,视图是虚拟的表,以表形式呈现的是你查询的结果。并不是说在数据库里面真的存在这个表,但是是真的存在这些数据。

select cust_name,cust_contact

from customers ,orders,orderitems

where customers.cust_id=orders.cust_id

and orderitems.orderitems.order_num=orders.order_num

and prod_id='tnt2';

 

P158

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;

#先建立名为productcustomers的视图,联结了三个表#

select cust_name,cust_contact from productcustomers where prod_id ='tnt2'; 

#先在上面的语句建立了视图productcustomers,然后在视图里面提取prod_id='tnt2'对应的cust_name,cust_contact #

 

 其他的类似

 

posted @ 2018-08-09 20:59  张三疯了  阅读(131)  评论(0编辑  收藏  举报