我有下表,我想获得所有产品的总数:
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
我有下表,我想获得所有产品的总数:
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
SELECT SUM(Qty) AS TOTAL
FROM [TABLE_NAME]
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