首页 > 数据库 > 数据库开发技术 > 更多报表/分析决策功能
SELECT salesperson_id, SUM(tot_sales) sp_sales,
RANK( ) OVER (ORDER BY SUM(tot_sales) DESC) sales_rank
FROM orders
GROUP BY salesperson_id
SELECT cust_nbr, SUM(tot_sales) cust_sales,NTITLE(4)把纪录以 SUM(tot_sales)排序分成4份.
NTILE(4) OVER (ORDER BY SUM(tot_sales) DESC) sales_quartile
FROM orders
GROUP BY cust_nbr
ORDER BY 3,2 DESC;
SELECT month, SUM(tot_sales) monthly_sales,
SUM(SUM(tot_sales)) OVER (ORDER BY month
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) max_preceeding
FROM orders
GROUP BY month
ORDER BY month;
SELECT month, SUM(tot_sales) monthly_sales,
AVG(SUM(tot_sales)) OVER (ORDER BY month
ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) rolling_avg
FROM orders
GROUP BY month
ORDER BY month;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/8591181/viewspace-899276/ ,如需转载,请注明出处,否则将追究法律责任。