【问题标题】:VB.NET adding Rows and columnsVB.NET 添加行和列
【发布时间】:2014-10-27 13:22:11
【问题描述】:

我正在寻找一种在某个 date_code 中的不同列中添加多个金额的方法,我使用 select sum 在单个列中添加金额,但我不知道如何添加多个列行,如果你明白我的意思,我的sql数据库如下:

  Date       amount1    amount2    amount3    amount4    amount5
 02/10/2014    2            3           6           0           5
 02/10/2014    3            1           2           0           3
 02/10/2014    0            4           6           6           2
 02/10/2014    2            0           9           3           6
 02/10/2014    7            0           8           2           9

我需要同一日期范围内所有金额的总和。

总计:71

任何帮助都会很棒,

非常感谢, 皮特

这是我目前得到的添加金额的代码,但只在一列中:

connect() cmd.CommandText = "SELECT SUM(amount1) FROM sqlccmbuildtimecount WHERE datevar = '" & temp_day & "/" & temp_month & "/" & temp_year & "'"
    endvalue.Text = cmd.ExecuteScalar() disconnect()

我已将 temp_day 设置为“02”,将 temp_month 设置为“10”,将 temp_year 设置为“2014”

【问题讨论】:

  • 你必须更具体。您使用什么对象和工具?至少有一部分代码会很好。
  • 我改变了我的问题,干杯。
  • 我不确定是否理解这个问题,但你能做到“SELECT SUM(amount1) + SUM(amount2) + ... FROM ...”吗?

标签: mysql vb.net visual-studio-2010


【解决方案1】:

总和不是 71,应该是 89

就像 the_lotus 所说,

做:

SELECT SUM(amount1) + SUM(amount2) + SUM(amount3) + SUM(amount4) + SUM(amount5) FROM sqlccmbuildtimecount WHERE datevar = '" & temp_day & "/" & temp_month & "/" & temp_year & "'"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-19
    • 2012-12-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多