Sql Server 查询语句
經典的sql語句保存
?
select case 4-2 when 1 then 'one' when 2 then 'two' else 'more' end; select T.MediaCode,T.MediaName,sum(1) as total, sum(case T.state when 1 then 0 else 1 end) as '未處理', --如果T.state ==1 就統計為0 個數否則統計為1的個數 sum(case T.state when 1 then 1 else 0 end) as '已提交' from (select A.State,C.MediaCode,C.MediaName from NM_CustCateDate A join NM_NetDatas B on B.MediumTypeId=A.MediumTypeId and B.DataId=A.DataId left join NM_Medias C on C.MediumType=B.MediumTypeId and C.MediaCode=B.MediaCode where A.MediumTypeId=5 and B.PublicDate>='2000-01-01' and B.PublicDate<='2011-12-31') T group by T.MediaCode,T.MediaName -- cust.state=0 未處理 -- cust.state=1 已提交
?
select comp.Name_c,users.UserName,sum(1) as total, sum(case cust.state when 1 then 0 else 1 end) as '未處理', --如果T.state ==1 就統計為0 個數否則統計為1的個數 sum(case cust.state when 1 then 1 else 0 end) as '已提交' from NM_CustCateDate cust left join NM_Users users on cust.UserId=users.UserId left join NM_Company comp on cust.CustId=comp.CompanyID where comp.Date between '2010-12-10' and '2016-12-31' group by comp.name_c,users.UserName WITH ROLLUP -- cust.state=0 未處理 -- cust.state=1 已提交
select case 4-2 when 1 ?then 'one' ?when 2 then 'two' else 'more' end;
轉載于:https://www.cnblogs.com/java20130726/archive/2011/04/02/3218386.html
總結
以上是生活随笔為你收集整理的Sql Server 查询语句的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Xtreme ToolkitPro 编译
- 下一篇: DC概论四之setup time 与 h