PIVOT 未按预期执行
抱歉之前的问题不清楚;希望我可以重新开始...
我有这个数据:
entityid name stringvalue
----------- -------------------- --------------------
1 ShortDescription Coal
1 LongDescription BlackCoal
1 ShortDescription Gold
1 LongDescription WhiteGold
1 ShortDescription Steel
1 LongDescription StainlessSteel
这个查询:
select *
from
(
select entityid, name, stringvalue as stringvalue
from mytable
) as d
pivot
(
min([stringvalue])
for [name] in ([ShortDescription],[LongDescription])
)
as p
产生这个输出:
entityid ShortDescription LongDescription
-------- ---------------- ---------------
1 Coal BlackCoal
有人能告诉我为什么其他行没有被产生吗?我期待看到:
entityid ShortDescription LongDescription
-------- ---------------- ---------------
1 Coal BlackCoal
1 Gold WhiteGold
1 Steel StainlessSteel
Sorry for an unclear question previously; hopefully I can start again...
I have this data:
entityid name stringvalue
----------- -------------------- --------------------
1 ShortDescription Coal
1 LongDescription BlackCoal
1 ShortDescription Gold
1 LongDescription WhiteGold
1 ShortDescription Steel
1 LongDescription StainlessSteel
And this query:
select *
from
(
select entityid, name, stringvalue as stringvalue
from mytable
) as d
pivot
(
min([stringvalue])
for [name] in ([ShortDescription],[LongDescription])
)
as p
Producing this output:
entityid ShortDescription LongDescription
-------- ---------------- ---------------
1 Coal BlackCoal
Could someone tell me why the other rows are not being produced, please? I was expecting to see:
entityid ShortDescription LongDescription
-------- ---------------- ---------------
1 Coal BlackCoal
1 Gold WhiteGold
1 Steel StainlessSteel
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案是这样的:
:)
缺陷是输入表的entityid 行应该分别为1、1、2、2、3、3。
中号
The answer turned out to be this:
:)
The flaw was that the input table should have had 1, 1, 2, 2, 3, 3 for the entityid rows, respectively.
M