【发布时间】:2025-12-20 09:20:10
【问题描述】:
我有一张这样的桌子
Index | FeatureType | FeatureExists
1 | BR | 0
1 | EI | NULL
1 | RD | NULL
1 | SEI | 0
1 | SNI | NULL
1 | SSI | 0
我想把它改成如下:
Index | BR | EI | RD | SEI | SNI | SSI
1 | 0 | NULL | NULL | 0 | NULL | 0
这就是我在 Microsoft Access 应用程序中使用的代码:
TRANSFORM First(QueryFeatureLicenses.FeatureExists) AS PremierDeFeatureExists
SELECT QueryFeatureLicenses.Index AS [Index]
FROM QueryFeatureLicenses
GROUP BY QueryFeatureLicenses.Index
PIVOT QueryFeatureLicenses.FeatureType;
它就像一个魅力。
但是我应该如何用 SQL 语法转换这个查询呢?到目前为止'我已经做到了:
SELECT BR, EI, RD, SEI, SNI, SSI
FROM
(
SELECT FeatureType, FeatureExists
FROM QueryFeatureLicenses
) AS d
PIVOT
(
max(FeatureExists)
FOR FeatureType IN (BR,EI,RD, SEI,SNI,SSI)
) AS piv;
但我总是收到以下消息:
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在“PIVOT”附近使用的正确语法 ( 最大(功能存在) FOR FeatureType IN (BR,EI,RD, SEI,SN' 在第 7 行
有什么想法吗?
【问题讨论】:
标签: mysql sql ms-access pivot pivot-table