数据分组及查范围-NTILE


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

WITH orderdata AS(
SELECT bo.OrderNo,bo.OrderDate,bo.Amount,
NTILE(10) OVER (ORDER BY bo.Amount) groupid
FROM bdOrder bo
WHERE bo.OrderDate >=’2011-05-24′ AND bo.OrderDate < '2011-05-25' ) --分为10个组,每组上限与下限,及个数 SELECT a.groupid,MIN(amount),MAX(amount),COUNT(1) FROM orderdata a GROUP BY a.groupid 注:当组数无法整除行数时,前面的r个组比其它组多一行。如有11行,分3个组,那么前两个组分别有4个,后一个组有1个。