我将重新发布此内容并添加其他信息。我正在处理一个sql查询,使用pivot并遇到了一个问题。pivot表中的列实际上显示为行数据,并且对每个服务器都是重复的。
WITH agg AS
(
select NodeID,
count(distinct cpuindex) as number_of_cpu,
case
when count(distinct cpuindex) < 8 THEN 1
else count(distinct cpuindex) / 8
end AS number_of_cores
from CPUMultiLoad_Detail
where nodeid in (select nodeid from nodesdata)
group by NodeID
)
SELECT * FROM (
SELECT cp.Environment, n.Caption,
cs.ComponentName,cs.ComponentStatisticData, cs.ErrorMessage,
agg.NodeID, agg.number_of_cpu, agg.number_of_cores, n.description
FROM APM_CurrentStatistics cs
INNER JOIN APM_Application app
ON cs.ApplicationID = app.ID
AND app.Name IN ('Oracle Database Licensing')
INNER JOIN NodesData n
ON cs.NodeID = n.NodeID
AND n.description NOT LIKE '%Windows%'
INNER JOIN NodesCustomProperties cp
ON cp.NodeID = n.NodeID
INNER JOIN agg
ON cs.NodeID = agg.NodeID
) t
PIVOT(
max(cs.ErrorMessage) FOR cs.ComponentName IN (
[Oracle Version],
[Oracle Partitioning],
[Oracle Tuning Pack],
[Diagnostic Pack],
[Real Application Clusters (RAC)])
) AS pivot_table;
期望输出
我收到错误消息107,级别15,状态1,第30行列前缀“cs”与查询中使用的表名或别名不匹配。msg 107,level 15,state 1,line 30列前缀“cs”与查询中使用的表名或别名不匹配。
任何帮助都将不胜感激。
1条答案
按热度按时间8ljdwjyq1#
把这两个拿出来
cs.
在这条线上它将前面的select语句视为已经运行过,因此不需要消除这些列名的歧义