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 |
tinamiller1
Yak Posting Veteran
78 Posts |
Posted - 2015-03-13 : 12:20:47
|
I have a table that has 565789 distinct rows and I am tring to get the maximum value across several columns. This is an example of my data:mid value1 value2 value3 value4 value5 value6111 .034 .005 .036 .010 .012 .002222 .054 .032 .001 .002 .005 .006333 .002 .004 .006 .001 .003 .087The query I am trying is: and it states invalud from but not sure whySELECT MID(SELECT MAX(VAL) FROM (SELECT A.VALUE1 FROM A UNION ALLSELECT B.VALUE2 FROM B UNION ALLSELECT C.VALUE3 FROM C UNION ALLSELECT D.VALUE4 FROM D UNION ALLSELECT E.VALUE5 FROM E UNION ALLSELECT F.VALUE6 FROM F UNION ALL) AS VAL)AS MAXVALFROM MEMBER ZINNER JOIN Z.MID = A.MIDINNER JOIN Z.MID = B.MIDINNER JOIN Z.MID = C.MIDINNER JOIN Z.MID = D.MIDINNER JOIN Z.MID = E.MIDINNER JOIN Z.MID = F.MID; tina m miller |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2015-03-13 : 12:31:53
|
[code]select mid, max(val)from MEMBER cross apply ( select value1 union all select value2 union all select value3 union all select value4 union all select value5 union all select value6) v(val)group by mid[/code] |
|
|
tinamiller1
Yak Posting Veteran
78 Posts |
Posted - 2015-03-13 : 13:52:14
|
Thanks. That was the ticket.tina m miller |
|
|
|
|
|