-1

我正在寻找一个查询,它将views根据单个用户的id.

这是表格的内容:

id |  post_id | user_id | views

1 |      4     |   67    | 4
1 |      56     |   67    | 3
1 |      34     |   67    | 10

我想获取用户拥有的帖子视图总数

SELECT *,count(views) from users WHERE user_id = 67

结果必须是17

4

3 回答 3

2
SELECT user_id, sum(views) FROM users WHERE user_id = 67 GROUP BY user_id
于 2012-06-11T13:24:00.730 回答
1

你想要SUM运营商。

SELECT SUM(views) FROM users WHERE user_id = 67
于 2012-06-11T13:24:41.127 回答
1

只是SUM意见:

简单的方法:

SELECT SUM(views) 
FROM users
WHERE user_id = 67;

更复杂的方法:

SELECT user_id, SUM(views) 
FROM users
WHERE user_id = 67
GROUP BY user_id;
于 2012-06-11T13:24:52.273 回答