SQL Server 交叉表查询 case

2023年 4月 17日 42.9k 0

代码如下所示: 表landundertake结构如下所示: 表appraiser结构如下所示: access代码: 复制代码 代码如下: TRANSFORM First(Landundertake.valuerId) AS valuerId之First SELECT Appraiser.quarterId, Landundertake.l

代码如下所示:

表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 交叉表查询结果如下所示:

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论