sql中over用法

作者: Quick_5413 | 来源:发表于2021-01-22 14:56 被阅读0次

累加当日、昨日、明日:

select a,b,sum(c) over(partition by a order by b rows between 1 preceding and 1 following) from t

累加当日和昨天:
select a,b,sum(c) over(partition by a order by b rows between 1 preceding and current row) from t

累加历史:分区内当天及之前所有
select a,b,sum(c) over(partition by a order by b) from t
或者:
select a,b,sum(c) over(partition by a order by b rows between unbounded preceding and current row) from t

累加分区内所有:当天和之前之后所有

select a,b,sum(c) over(partition by a order by b rows between unbounded preceding and unbounded following) from t

相关文章

网友评论

    本文标题:sql中over用法

    本文链接:https://www.haomeiwen.com/subject/gogszktx.html