程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> 其他數據庫知識 >> 更多數據庫知識 >> SQL Server 交叉表查詢 case

SQL Server 交叉表查詢 case

編輯:更多數據庫知識

代碼如下所示:

表landundertake結構如下所示:

表appraiser結構如下所示:

access代碼:
復制代碼 代碼如下:
TRANSFORM First(Landundertake.valuerId) AS valuerId之First
SELECT Appraiser.quarterId, Landundertake.landCode
FROM Landundertake INNER JOIN Appraiser ON (Landundertake .valuerId = Appraiser.valuerID) AND (Landundertake .quarterId = Appraiser.quarterId)
GROUP BY Appraiser.quarterId, Landundertake .landCode
PIVOT Landundertake .valuerGrade;

SQL server代碼:
復制代碼 代碼如下:
select dbo.appraiser.quarterID,dbo.landUndertake.landcode,case dbo.landUndertake.appraiserGrade when 'appraiserID1' then dbo.landundertake.appraiserID else null END as appraiserID,case dbo.landUndertake.appraiserGrade when 'appraiserID2' then dbo.landundertake.appraiserID else null END as appraiserID1
from dbo.LandUndertake inner join
dbo.Appraiser ON dbo.LandUndertake.quarterID=dbo.appraiser.quarterID and dbo.landundertake.appraiserID=DBO.Appraiser.appraiserID
Group by dbo.appraiser.quarterID,dbo.landUndertake.landcode,dbo.landundertake.appraiserGrade,dbo.landundertake.appraiserID
交叉表查詢結果如下所示:

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved