ProductId | BrandId | Views
1 | 1 | 3
2 | 1 | 2
3 | 2 | 3
4 | 2 | 4
Need write sql query to return this values:
BrandId | ViewsSummary
1 | 5
2 | 7
Please, how to do it?
It's hardly "tricky" - you're simply looking to group your results with an appropriate aggregate function :
SELECT BrandId, SUM(Views) AS ViewsSummary FROM my_table GROUP BY BrandId
See it on sqlfiddle .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.