开窗函数

开窗函数是在分组上作用,结果是为表增加了一个新列。
如:统计顾客的月购买总额和购买明细。

  1. select
  2. name,
  3. orderdate,
  4. cost,
  5. sum(cost) over(partition by name,month(orderdate)) name_month_cost
  6. from business;

image.png