Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
sadaiyan
Starting Member
6 Posts |
Posted - 2008-07-28 : 12:33:30
|
hello, i want to get three fields max value like max(a),max(b) and max(c) and finally i want to get the maximum value of those three value...can anyone suggest a solution please..sadaiyan.l |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-28 : 12:51:23
|
[code]SELECT MAX(CASE WHEN Seq=1 THEN [Value] ELSE NULL END) AS MaxA,MAX(CASE WHEN Seq=2 THEN [Value] ELSE NULL END) AS MaxB,MAX(CASE WHEN Seq=3 THEN [Value] ELSE NULL END) AS MaxC,MAX([Value]) AS MaxAllFROM(SELECT a as Value,1 AS SeqFROM YourTableUNION ALLSELECT b,2FROM YourTableUNION ALLSELECT c,3FROM YourTable)t[/code] |
|
|
sadaiyan
Starting Member
6 Posts |
Posted - 2008-07-30 : 12:45:43
|
Hello tkizer,Thanks to reply me, in this solution what is dtselect max(MaxColumn) as MaxColumnfrom(select max(a) as MaxColumn from table union select max(b) from table union select max(c) from table) dtsadaiyan.lsadaiyan.l |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-30 : 21:03:26
|
quote: Originally posted by sadaiyan Hello tkizer,Thanks to reply me, in this solution what is dtselect max(MaxColumn) as MaxColumnfrom(select max(a) as MaxColumn from table union select max(b) from table union select max(c) from table) dtsadaiyan.lsadaiyan.l
Post to the wrong thread ? I don't see Tara's post here KH[spoiler]Time is always against us[/spoiler] |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2008-07-30 : 21:19:21
|
|
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-31 : 04:58:06
|
quote: Originally posted by khtan
quote: Originally posted by sadaiyan Hello tkizer,Thanks to reply me, in this solution what is dtselect max(MaxColumn) as MaxColumnfrom(select max(a) as MaxColumn from table union select max(b) from table union select max(c) from table) dtsadaiyan.lsadaiyan.l
Post to the wrong thread ? I don't see Tara's post here KH[spoiler]Time is always against us[/spoiler]
See herehttp://www.sqlteam.com/forums/topic.asp?TOPIC_ID=107555MadhivananFailing to plan is Planning to fail |
|
|
|
|
|
|
|