SQL Server 交叉表查询 case
SQL Server 交叉表查询 case
发布时间:2016-12-29 来源:查字典编辑
摘要:代码如下所示:表landundertake结构如下所示:表appraiser结构如下所示:access代码:复制代码代码如下:TRANSFO...

代码如下所示:

表landundertake结构如下所示:

SQL Server 交叉表查询 case1

表appraiser结构如下所示:

SQL Server 交叉表查询 case2

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

交叉表查询结果如下所示:

SQL Server 交叉表查询 case3

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新mssql数据库学习
热门mssql数据库学习
编程开发子分类