Mysql SQL sum与其他两列中的依赖项

Mysql SQL sum与其他两列中的依赖项,mysql,sql,postgresql,sum,Mysql,Sql,Postgresql,Sum,我有下表: -------------------------------------------------- | id | hear_about_us| bought_item_id | -------------------------------------------------- | 1 | friend | 1 | ----------------------------------------

我有下表:

--------------------------------------------------
| id | hear_about_us| bought_item_id             |
--------------------------------------------------
| 1  |     friend   | 1                          |
--------------------------------------------------
| 1  | internet     | 1                          |
--------------------------------------------------
| 2  | work         | 0                          |
--------------------------------------------------
| 3  | work         | 0                          |
--------------------------------------------------
实际情况要复杂得多,所以我简化了它。 我想根据这些家伙来自哪里数一数。 所以如果我这样做了

SELECT heard_about_us, SUM(bought_items) as sold FROM table GROUP BY heard_about_us
此项计数两次,但它是同一项

如何根据买家的id计算所购买物品的金额


谢谢

尝试
选择关于我们的不同信息,按购买项目id从表组中销售的金额(购买项目)
您想要什么结果?你在使用什么数据库?只使用适当的标签。“买方id”是什么列?您的主键是什么?
SELECT id, SUM(bought_items) as sold FROM table GROUP BY id