SQL - 每周分区
假设员工数据集要大得多。我们希望按周范围对员工加入的日期进行分区,但仅限于过去 6 个月,
我们该怎么做?
这是预期的结果。
我们看到第 1 行和第 2 行落在相同的周范围内,并且被划分在一起。第 3 行是该周的唯一值,因此它本身为 1。第 4 行和第 5 行属于同一周范围,因此它们为 2。第 6 行不属于 6 个月范围,因此为 0。
< a href="https://i.sstatic.net/8FjyN.png" rel="nofollow noreferrer">
select id,name,date, count(*) over (partition by Date)
from employee
Assume the employee dataset is much larger. And we want to partition on a weekly range the date an employee joined, but only for the last 6 months
How would we do that?
Here is expected result.
We see row 1&2 fall in same weekly range and are partitioned together. Row 3 is the only value of that week, so it is by itself as 1. Row 4&5 fall in the same weekly range, therefore they are 2. And row 6 does not fall within a 6 month range, therefore 0.
select id,name,date, count(*) over (partition by Date)
from employee
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用这个
use this