如何从sql server 2000中的多个列中选择最大值 [英] how to select the maximum value from multiple columns in sql server 2000
本文介绍了如何从sql server 2000中的多个列中选择最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有三列名为
mark1,mark2,mark3(例如:80,86,69),我需要从这三个值中选择最大值并将它们放入一个新的列什么是用于在多列中选择最大值的sql查询请告诉我........
I am having three column named
mark1,mark2,mark3 (for eg:80,86,69) , i need to select the maximum values from these three values and put them in a new column what is the sql query for selecting maximum values among multiple columns please hellp me........
推荐答案
它应该有效:
It should works:
SELECT MAX(T.Age) AS MaxOfAge
FROM (
SELECT mark1 AS Age
FROM YourTable
UNION ALL
SELECT mark2 AS Age
FROM YourTable
UNION ALL
SELECT mark3 As Age
FROM YourTable) AS T
想法:从3个不同的列中获取数据in to one然后获得最大值;)
Idea: fetch data from 3 different columns in to one and then get the maximum ;)
SELECT (select MAX(myval) from (values (mark1),(mark2),(mark3)) as D(myval)) AS 'MaxMarks'
FROM
YourTable
尝试以下查询: -
try below query:-
select
case when marks1 > marks2 and marks1 > marks3 then marks1
when marks2 > marks1 and marks2 > marks3 then marks2
else marks3
end
from
exam
这篇关于如何从sql server 2000中的多个列中选择最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文