繁体   English   中英

如何使用不同的条件从同一列中获取数据?

[英]How to fetch data from same column using different criteria?

嗨,我在 SQL anywhere 数据库中有这样的表

CUSTID-------DDAT.----------AMOUNT
1.         01-01-2021.       1000
1.         02-02-2021.       2000
1.         03-02-2021.       3000
1.         04-02-2021.       4000
2.         01-04-2021.        1000
2.         02-04-2021.         2000
  1.  04-04-2021. 1000

我想要 VB.net 中这样的数据,其中金额仅为一个日期,总金额为 4 天

Cust id.------date ---------------Amount.-------Total amount
1.             04-04-2021.          4000.                 10000
 2.             04-04-2021.          1000.                 4000

你能给我任何解决方案吗..提前致谢

我的看法:

select custid, dat, amount, total_amount
from (
    select custid, dat, amount, sum(amount) over (partition by custid) as total_amount
    from data
) d
where dat = '2021-04-04' -- or any other date

可能是内部 select 就是您所需要的。 不确定是否需要按日期过滤。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM