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

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


 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值