SQL 中一组 100 列的每行最大值
虽然我看到过这个问题的几个答案,但它们都倾向于依赖于最大的函数,该函数不断返回
“Msg 195,Level 15,State 10,Line 1” 'GREATEST' 不是公认的内置函数名称。”
我想知道一种构建查询的方法,该查询为每一行返回工件 id,以及该行中的最大值及其所在列。任何欢迎提出建议。我已经查看了此板上和其他板上的相当多的示例,但不断遇到各种错误,
为了查看的乐趣而缩短:
SELECT artifactID, GREATEST(V0,V1,V2,V3,V4,V5,V6...V98,V99) AS col_value,
CASE GREATEST(V0,V1,V2,V3,V4,V5,V6...V98,V99)
WHEN V0 THEN '0'
WHEN V1 THEN '1'
WHEN V2 THEN '2'
WHEN V3 THEN '3'
...
WHEN V99 THEN '99'
END AS col_name
FROM dbo.Theta
我希望查询返回的示例:
ArtifactID GreatestColumnValue ColumnValueCameFrom
00001 .330 59
00002 .89 89
...
01000 .44 7
谢谢!
While I have seen several answers to this question all of them tend to rely on on the greatest function which keeps coming back with a
"Msg 195, Level 15, State 10, Line 1
'GREATEST' is not a recognized built-in function name."
I would like to know a way to build a query that for each row returns the artifact id, and the greatest value in the row along with the column it was in. Any suggestions would be welcome. I've looked over quite a few example on this board and others but keep runnign across various errors.
Attempted and Failed Code, shortened for veiwing pleasure:
SELECT artifactID, GREATEST(V0,V1,V2,V3,V4,V5,V6...V98,V99) AS col_value,
CASE GREATEST(V0,V1,V2,V3,V4,V5,V6...V98,V99)
WHEN V0 THEN '0'
WHEN V1 THEN '1'
WHEN V2 THEN '2'
WHEN V3 THEN '3'
...
WHEN V99 THEN '99'
END AS col_name
FROM dbo.Theta
Example of what I would like query to return:
ArtifactID GreatestColumnValue ColumnValueCameFrom
00001 .330 59
00002 .89 89
...
01000 .44 7
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)