如果另一列的条件是未满足的,则排除组
这是我正在处理的简单示例。我是通过将另一个临时表与数据库中存储的表连接在一起来创建一个临时表(a)。我有以下临时表(a)的输出:
名称 | 日期 | 美元 |
---|---|---|
a | 2022-06-01 | $ 500 |
a | 2022-05-01 | $ 250 |
$ 250 A | 2022-04-01 | $ 100 $ 100 |
A | 2022-03-03-01 | $ 475 |
B | 20222-06-06-01 | $ 180 $ 180 |
b | 2022-05-01 | $ 30 |
B | 2022-04-01 | $ 360 |
... | ... | ... |
我的最终目标是按“美元”和“名称”组成。但是,如果该组的最早记录日期从今天的日期开始超过3个月,我只希望最终输出包括“名称”。因此,在上面的情况下,我想将“ a”包含在内,并将“美元”加在一起,但我想排除B,因为它不符合我的状况。我该怎么做?
这就是我希望我的最终输出是什么;
名称 | 日期 | $ |
---|---|---|
a | 2022-06-01 | 1375 |
... | 2022-06-01 | ... |
This is a simplified example of what I'm dealing with. I'm creating a temp table (a) by joining a different temp table with a table stored in the database. I have the following output for temp table (a):
name | date | dollars |
---|---|---|
A | 2022-06-01 | $500 |
A | 2022-05-01 | $250 |
A | 2022-04-01 | $100 |
A | 2022-03-01 | $475 |
B | 2022-06-01 | $180 |
B | 2022-05-01 | $30 |
B | 2022-04-01 | $360 |
... | ... | ... |
My ultimate goal is to sum 'dollars' and group by 'name'. However, I only want my final output to include 'name' if the earliest recorded date for the group is more than 3 months from today's date. So in the case above, I would want to include 'A' and sum the 'dollars' together, but I want to exclude B because it does not meet my condition. How can I do that?
This is what I want my final output to be;
name | date | dollars |
---|---|---|
A | 2022-06-01 | $1375 |
... | 2022-06-01 | ... |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用这样的案例指令
You can use the case instruction like this
这个可以工作吗?
Could this work?
您想报告所有几个月的每月总计,但仅针对那些带有数据恢复超过三个月的名称。
或者
You want to report monthly totals for all months but only for those names with data going back more than three months.
Or