1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| # 以一个列子来说明 jack,2017-01-01,10 tony,2017-01-02,15 jack,2017-02-03,23 tony,2017-01-04,29 jack,2017-01-05,46 jack,2017-04-06,42 tony,2017-01-07,50 jack,2017-01-08,55 mart,2017-04-08,62 mart,2017-04-09,68 neil,2017-05-10,12 mart,2017-04-11,75 neil,2017-06-12,80 mart,2017-04-13,94
# 不加over的情况下: select name,count(*) from business where substring(orderdate, 1, 7)='2017-04' group by name; jack 1 mart 4 # 加了over()的情况下:这个over相当于 # 先select * from business where xxxxx group by name; # 看当前有两行,over对这两行进行计算count select name,count(*) over () from business where substring(orderdate,1,7) = '2017-04' group by name; mart 2 jack 2
# 查询顾客的 购买明细 及 购买总额 select *,sum(cost) over() from business;
# over()里面group by只能用于第一条数据到现在的数据,这一种情况 select *,sum(cost) over(distribute by name sort by orderdate) from business;
# 查询顾客的 购买明细 及 月购买总额 select *,sum(cost) over(partition by month(orderdate)) from business;
|