视图的使用

一丶例1

 1 CREATE VIEW v_billonline
 2 as 
 3 
 4 select rb.Area,rb.ProjectId,rb.ProjectName,
 5 rb.FloorNumber,rb.FormatsName,rb.TwoFormatsName,
 6 rb.BunkNo,rb.BrandAbbreviation,s.BusinessManager,
 7 s.StoreManager,s.StoreManagerPhone,
 8 rb.BillYear,rb.BillMonth,rb.ThisReceivable as RentReceivable,
 9 rb.BillStatus as RentBillStatus,rb.F_ID as RentBilld, 
10 pb.ThisReceivable as PropertReceivable,pb.BillStatus as PropertBillStatus,
11 pb.F_ID as  PropertBillId
12 from he_finance_rentbill rb                                  -- 1
13 LEFT JOIN he_finance_propertybill pb  
14 on rb.PlanId=pb.PlanId  and rb.BillYear = pb.BillYear and rb.BillMonth= pb.BillMonth        -- 2
15 LEFT JOIN he_merchants_store s on rb.PlanId=s.PlanId;
View Code

 二

 1 with he_operating_LicenceManageInfoS as(
 2 
 3 select 'DP1' dp ,'z1' as LicenseType,'2018-1-1' as LicenseValidityDate
 4 union all select 'DP1','z2','2018-2-1'
 5 union all select 'DP1','z3','2018-3-1'
 6 union all select 'DP1','z4','2018-4-1'
 7 union all select 'DP2','z1','2018-1-1' 
 8 union all select 'DP2','z4','2018-4-1'
 9 union all select 'DP3','z1','2018-1-1' 
10 union all select 'DP3','z2','2018-4-1'
11 union all select 'DP3','z3','2018-1-1' 
12 union all select 'DP3','z4','2018-4-1'
13 union all select 'DP3','z5','2018-1-1' 
14 union all select 'DP3','z5','2018-4-1'
15 )
16 
17 -- select distinct LicenseType from he_operating_LicenceManageInfoS;
18 
19 select StoreNo,
20 max(case when LicenseType='z1' then LicenseValidityDate else '' end)  as 'z1',
21 max(case when LicenseType='z2' then LicenseValidityDate else '' end)  as 'z2',
22 max(case when LicenseType='z3' then LicenseValidityDate else '' end)  as 'z3',
23 max(case when LicenseType='z4' then LicenseValidityDate else '' end)  as 'z4',
24 max(case when LicenseType='z5' then LicenseValidityDate else '' end)  as 'z5'
25 from he_operating_LicenceManageInfo 
26 group by StoreNo
27 
28 
29  
30 INSERT into he_operating_LicenceManageInfo (F_ID,StoreNo,LicenseType)
31 SELECT * from (
32 select newGuid() AS F_ID, t.StoreNo,t.LicenseType  from (
33   select StoreNo,LicenceName as LicenseType  from he_merchants_store
34     left join 
35     (select licencename from  he_operating_formatsandlicencerelational) s
36     on 1=1
37     where storeno !=''
38     order by storeno,LicenseType
39 )t 
40 left join he_operating_LicenceManageInfo as he on t.StoreNo = he.StoreNo
41 where he.StoreNo is NULL ) tt
42 
43 SELECT * FROM he_operating_LicenceManageInfo

 

转载于:https://www.cnblogs.com/chenze-Index/p/9959752.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值