您的位置:首页 > 数据库

【数据库SQL】创建SQL视图的使用案例

2017-01-03 12:58 302 查看
use hbposev9 --数据库名

go

--如果存在就先删除视图

if exists(select * from sys.views  where  name = 'view_name')

drop view view_name

go

--创建视图

CREATE VIEW view_name AS 

--查询语句

select a.item_clsno ,a.item_name,b.branch_no

,sum(b.real_qty)as 'APP订单数量',sum(c.real_qty) as '门店要货数量'

from t_bd_item_info a

full  join t_order_bill_weixin b on(A.item_no=B.item_no)

full  join t_pm_sheet_detail c on(A.item_no=c.item_no)  

where (b.real_qty+c.real_qty)<>0 

and b.branch_no like '%%'

and c.sheet_no like 'YH%'

group by a.item_clsno,a.item_name,b.branch_no

go

--最后直接就可以查询此视图

select * from view_name

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: