sql的max之類的聚合函數只能針對同一列的n行運算
/*
測試名稱
測試功能
運行原理
*/
declare @t table (
id smallint
a smallint
c smallint
e smallint
insert into @t
select
select
select a
from @t a outer apply(
select doc=(
select * from @t as doc where id= a
) b
outer apply(
select
min ( r) as minValue
max ( r) as maxValue
sum ( r) as sumValue
avg ( r) as avgValue
from (
select cast ( cast ( d
from doc
) c
/* 測試結果
id a b c d e f minValue maxValue sumValue avgValue
*/
From:http://tw.wingwit.com/Article/program/MySQL/201311/29537.html