中值:若总数为奇数,则中数为中间那个,若为偶数,则为中间两个平均 WITH RN AS(
SELECT CONVERT(VARCHAR(10),a.OrderDate,120) OrderDate,amount,
ROW_NUMBER () OVER ( PARTITION BY CONVERT(VARCHAR(10),a.OrderDate,120) ORDER BY a.Amount,a.id) rx,
ROW_NUMBER () OVER ( PARTITION BY CONVERT(VARCHAR(10),a.OrderDate,120) ORDER BY a.Amount DESC,a.id DESC ) rl
FROM bdOrder a(NOLOCK)WHERE a.OrderDate >='2011-05-01' )
注:正序与倒序排,因为Amount值相同的情况,故要加id决定决胜因子。