日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
SQLServer數(shù)據(jù)庫中如何合并表格數(shù)據(jù)

SQL Server數(shù)據(jù)庫是如何合并表格數(shù)據(jù)的呢?其實SQL Server數(shù)據(jù)庫合并表格數(shù)據(jù)是利用ROW_NUMBER來實現(xiàn)的,本文我們通過一個例子來介紹如何合并表格數(shù)據(jù)。我使用的數(shù)據(jù)庫版本是SQL Server 2005,表格的原始數(shù)據(jù)如下:

這個一個學習和測試的記錄,Type是類型(0學習,1測試)。一天中可能會學習多次,也可能會測試多次,學習次數(shù)和測試次數(shù)可能不一樣。

想要的到得是,按日期列出當天學習和測試的記錄。

類似這樣的結果:(圖中兩行數(shù)據(jù)一樣,是兩種語言表示)

主要的SQL語句如下:

 
 
 
 
  1. select A.Date,A.MID,A.Contents1,B.Contents2,B.Passed from
  2. (select ROW_NUMBER() over(partition by Date order by Date) as MID,Date,Contents as Contents1 from History where Type=0 ) A
  3. left join 
  4. (select ROW_NUMBER() over(partition by Date order by Date) as MID,Date,Contents as Contents2,Passed from History where Type=1 ) B
  5. on A.Date=B.Date and A.MID=B.MID
  6. union
  7. select  B.Date,B.MID, A.Contents1,B.Contents2,B.Passed from
  8. (select ROW_NUMBER() over(partition by Date order by Date) as MID,Date,Contents as Contents1 from History where Type=0 ) A
  9. right join 
  10. (select ROW_NUMBER() over(partition by Date order by Date) as MID,Date,Contents as Contents2,Passed from History where Type=1) B
  11. on A.Date=B.Date and A.MID=B.MID

結果如下:

至此,表格的數(shù)據(jù)已經(jīng)合并完畢了。

關于SQL Server數(shù)據(jù)庫合并表格數(shù)據(jù)的知識就介紹到這里,如果您想了解更多關于SQL Server數(shù)據(jù)庫的知識,可以看一下這里的文章:http://database./sqlserver/,相信一定會帶給您收獲的!


當前文章:SQLServer數(shù)據(jù)庫中如何合并表格數(shù)據(jù)
網(wǎng)頁路徑:http://www.dlmjj.cn/article/cdisodi.html