【问题标题】:How to fetch data from same column using different criteria?如何使用不同的标准从同一列中获取数据?
【发布时间】:2021-08-20 12:04:45
【问题描述】:

您好,我在 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

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

【问题讨论】:

  • 你知道你想要哪个日期吗?为什么第一列与第二列不匹配?
  • “我尝试了很多 SQL 查询”。如果我们看不到它,那么它就没有发生。向我们展示您认为应该有效的一种尝试。这就是这个网站的运作方式。这不是“我想做X,告诉我怎么做”。这是“我想做X,这就是我正在尝试的方式,告诉我如何解决它”

标签: sql vb.net sqlanywhere


【解决方案1】:

我的看法:

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

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

【讨论】:

    猜你喜欢
    • 2019-12-14
    • 1970-01-01
    • 2015-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    相关资源
    最近更新 更多