日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

T-sql 查询

發布時間:2025/3/21 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 T-sql 查询 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

------------------case---when-------的使用---------------------

select? userAccount , eatingDate ,
?? ?case when sum(a)=1 then'早餐' else '' end?? as 'breakfast' ,
?? ?case when sum(b)=1 then '午餐' else '' end? as 'lunch',
?? ?case when sum(c)=1 then '晚餐' else '' end? as 'dinner'
?? ?from (
?? ??? ?select? userAccount , eatingDate ,
?? ??? ??? case when menuType='早餐' then 1 else 0 end? AS a ,
?? ??? ??? case when menuType='午餐' then 1 else 0 end? AS b ,
?? ??? ??? case when menuType='晚餐' then 1 else 0 end? AS c
?? ??? ?from view_menuReservation
?? ??? ??? where userAccount = '7923'
?? ??? ??? and eatingDate between '2016-12-01' and'2016-12-31'
?? ?) t ?
?? ?group by userAccount ,eatingDate
??? order by eatingDate asc

---------------------查詢的時候嵌套子查詢-----------------------------------------

SELECT tb.account, '2016-10'? month,
??? ( max(CASE signStatus WHEN '準時' THEN total ELSE 0 END )+
?? ? max(CASE signStatus WHEN '調休' THEN total ELSE 0 END)+
?? ? max(CASE signStatus WHEN '遲到' THEN total ELSE 0 END)
?? ? ) sumDay,
??? (max(CASE signStatus WHEN '準時' THEN total ELSE 0 END)
?? + max(CASE signStatus WHEN '調休' THEN total ELSE 0 END)) onTime,
???? max(CASE signStatus WHEN '遲到' THEN total ELSE 0 END) late,
???? max(CASE signStatus WHEN '請假' THEN total ELSE 0 END) leave,
???? max(CASE signStatus WHEN '早退' THEN total ELSE 0 END) absenteeism,
??? ( select count(*) from tb_workAttendance
where workStatus='加班' and
docdate between '2016-10-1' and '2016-10-31' and account = tb.account and signType='上班'? group by workStatus) overtime,
?? ?0 dayOff,
?? ?(select sum (totalHour) totalHour? from tb_restApply where? docdate between '2016-11-01' and '2016-11-30' and account=tb.account group by account) totalHour
???? from(
???? select count(1) total, signStatus, account
???? from tb_workAttendance
???? where docdate between '2016-10-1' and '2016-10-31'
???? group by signStatus,account)
???? tb
???? group by account

?

----------------------sql循環-------------------------------------------------------------

?declare @Num int;


set @Num = 1 ;
while @Num< 10
BEGIN
?? ?select '1';
?? ?set @Num = @Num +1 ;
END

-----------------T sql--------批量處理修改數據 數據來源別的關聯表------------------------------

?update GL_Journal? set madedate=b.madedate? from
(select madedate,id,accountingperiod?? from GL_Doc where maker ='admin' and accountingperiod ='12'? ) b
inner join GL_Journal a on a.docid =b.id

?-------------------------------------------------------數據表格的備份

select * into dddd from aaaa

?

轉載于:https://www.cnblogs.com/cl1006/p/6241067.html

總結

以上是生活随笔為你收集整理的T-sql 查询的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。