Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
ProductId | BrandId | Views 1 | 1 | 3 2 | 1 | 2 3 | 2 | 3 4 | 2 | 4
需要编写 sql 查询来返回此值:
BrandId | ViewsSummary 1 | 5 2 | 7
请问,怎么办?
这几乎不是“棘手” - 您只是希望使用适当的聚合函数对结果进行分组:
SELECT BrandId, SUM(Views) AS ViewsSummary FROM my_table GROUP BY BrandId
在sqlfiddle上查看。