汇总函数不会汇总 - 使用总和函数汇总数据集
我是Snowflake的新手,我正在尝试编写一个SQL查询,该查询将根据ref Ref
列总结2行。总和函数似乎不起作用,因为我认为我缺少一些东西。
示例数据(交易)
| id | withdraw| pending| ref | Status | date |
|:---- |:-------:| --- --:| -------:|---------:|---------:|
| 100 | 500 | -500 |1234:234 |Confirmed |2022-05-04 |
| 100 | -500 | 500 |1234:234 |Pending |2022-05-03 |
我想
| id | withdraw| pending| ref | Status | date |
|:---- |:-------:| --- --:| -------:|---------:|---------:|
| 100 | 0 | 0 |1234:234 |Confirmed |2022-05-04 |
在这里实现的目标是我到目前为止所做的
select id,
sum(withdraw),
sum(pending),
ref,
status,
date,
from transaction
group by id,ref
I am new to snowflake and I am trying to write an SQL query that would sum up 2 rows based on the ref
column. The sum function seems to not work as I think im missing something.
sample data (transaction)
| id | withdraw| pending| ref | Status | date |
|:---- |:-------:| --- --:| -------:|---------:|---------:|
| 100 | 500 | -500 |1234:234 |Confirmed |2022-05-04 |
| 100 | -500 | 500 |1234:234 |Pending |2022-05-03 |
what I want to achieve
| id | withdraw| pending| ref | Status | date |
|:---- |:-------:| --- --:| -------:|---------:|---------:|
| 100 | 0 | 0 |1234:234 |Confirmed |2022-05-04 |
here is what I did so far
select id,
sum(withdraw),
sum(pending),
ref,
status,
date,
from transaction
group by id,ref
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想要的是
提取
和的总和,
以及最后的状态
anddate
periD
和ref
然后使用窗口函数:If what you want is the sum of
withdraw
andpending
and the laststatus
anddate
perid
andref
then use window functions: