日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

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

新聞中心

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

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

這個(gè)一個(gè)學(xué)習(xí)和測(cè)試的記錄,Type是類型(0學(xué)習(xí),1測(cè)試)。一天中可能會(huì)學(xué)習(xí)多次,也可能會(huì)測(cè)試多次,學(xué)習(xí)次數(shù)和測(cè)試次數(shù)可能不一樣。

想要的到得是,按日期列出當(dāng)天學(xué)習(xí)和測(cè)試的記錄。

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

主要的SQL語(yǔ)句如下:

 
 
 
 
  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

結(jié)果如下:

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

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


文章題目:SQLServer數(shù)據(jù)庫(kù)中如何合并表格數(shù)據(jù)
網(wǎng)址分享:http://www.5511xx.com/article/cdisodi.html