zoukankan      html  css  js  c++  java
  • 视图的使用

    一丶例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
    作者:chenze
    出处:https://www.cnblogs.com/chenze-Index/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
    如果文中有什么错误,欢迎指出。以免更多的人被误导。
  • 相关阅读:
    C#综合揭秘——细说事务
    软件项目管理流程总结
    WCF揭秘——自定义绑定
    WCF揭秘——共享数据契约
    反流程升职记
    .NET基础篇——利用泛型与反射更新实体(ADO.NET Entity Framework)
    先睹为快:Visual Studio 11测试版已于2.29在微软官方网站正式发布
    .NET基础篇——分部类和分部方法
    C#综合揭秘——深入分析委托与事件
    .NET基础篇——反射的奥妙
  • 原文地址:https://www.cnblogs.com/chenze-Index/p/9959752.html
Copyright © 2011-2022 走看看