db2 select语句,包含group和sum

时间:2015-05-29 14:25:51

标签: sql db2 db2-400

我在db2中有这个数据,我需要查询...

location | part | quantity
--------------------------
  loc1     TD3     300
  loc1     RA5       0
  loc2     MO2       8
  loc2     CY1       9
  loc2     BL5       6
  loc4     RA5      50
  loc4     PL5       5
  loc3     YT7       2
  loc3     UA9       5

结果集会返回'location's 'quantity''part's的所有'part' 小于10 location | total quantity ------------------------- loc2 23 loc3 7 Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$D$12" Or Target.Address = "$D$13" Or Target.Address = "$D$14" Or Target.Address = "$D$15" Then Call Room End If End Sub 不需要包含在结果集中。同样在结果集中,我想总计数量的总和。所以在上面的例子中,我会得到这个结果集。

Sub Room()
Dim lastRow As Long
If IsNumeric(Range("i17")) Then
If [I17] < 0 Then
 MsgBox "msg "
End If
End If
End Sub

这需要是数据库 db2

的SQL查询

1 个答案:

答案 0 :(得分:3)

我明白了。这与你的上一个问题并不完全相同。但这是对查询的一个小调整:

select location, sum(quantity)
from db2
group by location
having max(quantity) < 10;