當前位置:首頁 » 編程語言 » sql兩行合並

sql兩行合並

發布時間: 2023-02-05 14:57:10

『壹』 sql查詢時如何合並兩行數據,具體如下。

看樣子像sqlserver,就按sqlserver的寫了

創建測試表,數據:

createtabletest
(requestidint,
logidint,
operatedatevarchar(10),
operatetimevarchar(10),
operatorint);


insertintotestvalues(502,1372,'2018-06-13','16:16:03',155);
insertintotestvalues(502,1446,'2018-06-14','09:00:32',153);
insertintotestvalues(502,1472,'2018-06-14','09:33:07',157);
insertintotestvalues(502,1474,'2018-06-14','09:35:11',151);
insertintotestvalues(502,1657,'2018-06-14','15:17:10',153);
insertintotestvalues(502,1660,'2018-06-14','15:18:17',155);
insertintotestvalues(502,1661,'2018-06-14','15:19:01',153);
insertintotestvalues(502,1662,'2018-06-14','15:19:48',157);
insertintotestvalues(502,1677,'2018-06-14','15:31:34',151);
insertintotestvalues(502,1694,'2018-06-14','16:42:51',12);
insertintotestvalues(502,1709,'2018-06-14','18:08:45',9);
insertintotestvalues(502,1730,'2018-06-15','08:09:14',158);
insertintotestvalues(502,1732,'2018-06-15','08:09:16',157);

執行:

withtas
(selecttest.*,row_number()over()rnfromtest)
selectt1.requestid,t1.logid,cast(t1.operatedate+''+t1.operatetimeasdatetime)begintime,cast(t2.operatedate+''+t2.operatetimeasdatetime)endtime,t1..requestid=t2.requestidandt1.rn=t2.rn+1

查詢結果:

最後時間沒按你那種方式顯示,你那種到時候算操作時間也麻煩,還不如改成時間日期類型了。

『貳』 怎麼用SQL語句將一張表中ID相同的行的內容合並在一起

工具/材料:Management Studio。

1、首先在桌面上,點擊「Management Studio」圖標。

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:577
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:871
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:566
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:750
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:668
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:994
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:239
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:98
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:790
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:696