热线电话:13121318867

登录
2022-01-21 阅读量: 1152
聚合函数用于开窗函数

-- 聚合函数用于开窗函数

-- 查询所有订单总金额

select sum(amount) as 订单总金额 from order_tab;


select *,sum(amount) over() as 订单总金额 from order_tab;

#当over中没有指定分区、排序和滑动窗口范围时,表中所有记录为一个区,默认计算分区内的所有记录


-- 查询每个用户的订单总金额

select user_no,sum(amount) as 订单总金额

from order_tab

group by user_no;


select *,sum(amount) over(partition by user_no) as 订单总金额 from order_tab;

#当over中指定分区,但是没有指定排序和滑动窗口范围时,默认计算当前分区内的所有记录


56.2200
1
关注作者
收藏
评论(1)

发表评论
CDA168708
2022-01-21

0.0565 1 0 回复
推荐帖子
条评论