-1

我有下表,我想获得所有产品的总数:

prodcod | prodname | pricein | Qty | priceout

01      | Coca     | 12$     | 40  | 20$
02      | pepsi    | 6$      | 20  | 10$
03      | fanta    | 9$      | 50  | 15$
04      | M150     | 12$     | 10  | 20$

我想得到总数=120

4

2 回答 2

1
SELECT SUM(Qty) AS TOTAL

FROM [TABLE_NAME]
于 2013-11-07T17:27:30.323 回答
1

SQL 代码很简单:

SELECT SUM(Qty) FROM Products

从 vb.net 调用它:

Dim Quantity As Integer
Using cn As New SqlConnection("connection string here"), _
      cmd As New SqlCommand("SELECT SUM(Qty) FROM Products", cn)

    cn.Open()
    Quantity = DirectCast(cmd.ExecuteScalar(), Integer)
End Using
于 2013-11-07T17:27:43.530 回答