在SQL中找到每行所有列中的最大列 [英] Find Greatest of all columns per row in SQL
本文介绍了在SQL中找到每行所有列中的最大列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含一些数字列的表,我必须从每行的所有列中找到最大值.
目前,我正在使用此
I have a table which has some numeric columns and i have to find the greatest value from all column per row.
currently i am using this
SELECT
CASE
WHEN Col1 >= Col2 AND Col1 >= Col3 THEN Col1
WHEN Col2 >= Col1 AND Col2 >= Col3 THEN Col2
WHEN Col3 >= Col1 AND Col3 >= Col2 THEN Col3
ELSE Col1
END AS MaxVal
但是每次增加一列时,我都需要更改所有情况.
有没有大陆方法可以做到这一点. Oracle
中的最棒" 之类的东西
我正在使用SQL Server 2000.
谢谢
--Pankaj
but every time when one more column added i need to change all cases.
Is there any continent way to achieve this. Any thing like "greatest" in Oracle
I am using SQL Server 2000.
Thanks
--Pankaj
推荐答案
您可以从下面两个链接中获取想法.
http://www.sqlservercurry.com/2010/07/find-maximum-value-in-each-row-sql.html [ http://social.msdn.microsoft.com /Forums/zh-CN/transactsql/thread/007764d0-4a2d-4227-a4db-21fce471fbb3/ [
You can get idea from below two links.
http://www.sqlservercurry.com/2010/07/find-maximum-value-in-each-row-sql.html[^]
http://social.msdn.microsoft.com/Forums/en-US/transactsql/thread/007764d0-4a2d-4227-a4db-21fce471fbb3/[^]
Hope it helps.
这篇关于在SQL中找到每行所有列中的最大列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文