本月的Sql查询,以及已发送更多帖子的用户

时间:2013-03-22 08:47:44

标签: mysql sql

我正在尝试向用户显示本月有更多帖子添加到列表中。但是不起作用。

SELECT *,SUM(post_id) FROM `posts` Where YEAR(date) = YEAR(NOW()) AND MONTH(date) = MONTH(NOW()) GROUP BY user_id ORDER BY id DESC LIMIT 0 , 18

sql table data:

INSERT INTO `posts` (`id`, `api_id`, `user_id`, `group_id`, `message`, `mentioned`, `attached`, `posttags`, `comments`, `reshares`, `date`, `date_lastedit`, `date_lastcomment`, `ip_addr`) VALUES
(1, 0, 1, 0, 'text', 0, 0, 0, 0, 0, 1360378616, 0, 1360378616, 0);

1 个答案:

答案 0 :(得分:1)

您应该将select子句中的列名指定为group by子句中的列名 试试这个。

SELECT user_id,SUM(post_id) FROM `posts` Where YEAR(date) = YEAR(NOW()) AND MONTH(date) = MONTH(NOW()) GROUP BY user_id ORDER BY user_id DESC LIMIT 0 , 18