我试图将具有公共属性的表中两行的两个整数相加。这是表格:
=> select * from hello;
exname | location | numitems
------------------------------+-----------+----------
Notes | Gallery B | 10
Notes to Coins | Gallery C | 16
Silver Dollars | Gallery A | 9
Silver Dollars | Gallery D | 2
(4 rows)
我试图查询表格以创建一个结果,该结果包含两行exname =' Silver Dollars'与numitems结合起来,总结了这两行。
我正在尝试创建具有此结果的查询:
exname | numitems
------------------------------+----------
Notes | 10
Notes to Coins | 16
Silver Dollars | 11
(3 rows)
请注意,9和2总计为11.我该怎么做?
答案 0 :(得分:1)
这样可行。
select exname, sum(numitems) numitems
from hello
group by exname ;
答案 1 :(得分:1)
尝试这个
select exname, sum(numitems)as numitems
from hello
group by exname