SQL Max such aggregate functions can only be for the same column of n row operations, if the N column operations, generally use case statements to judge, if the column is relatively easy to write, the list of more trouble.
--------------------------------------------------------------------------------
/*
Test name: Using XML Find aggregations between arbitrary columns
Test functionality: Make min, Max, SUM, and AVG operations on a table's column data
How it works: After a field is merged into XML, an XQuery query is converted to a rowset
/
--Establish a measurement Test environment
declare @t table (
ID smallint,
a smallint, b smallint,
C smallint, D smallint,
e smallint, f smallint)
INSERT INTO @t
Select 1, 1, 2, 3, 4, 6, 7 UNION ALL
Select 2, 34, 45, 56, 5 4, 9, 6
--Test statement
Select A.*, c.*
from @t a outer apply (
Select doc= (
Select * from @t as Doc where id= an. ID for XML Path ('), type '
) B
Outer apply (
Select
min (r) as Minva Lue,
Max (R) as MaxValue,
sum (r) as Sumvalue,
Avg (r) as Avgvalue
from (
Select cast ( D. Query (' text () ') as varchar (max) as int) as R
from Doc. nodes ('/a,b, C,d,e,f ') d (n)) TT
) c
/* Test results
ID a b c d E F minvalue maxValue Sumvalue Avgvalue
--------------------------------------------------------------------------------------
1 1 2 3 4 6 7 1 7 3
2 MB 9 6 6 204
*/