-3

我试图向用户展示本月添加到列表中的更多帖子。但不起作用。

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表数据:

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);
4

1 回答 1

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
于 2013-03-22T08:52:32.413 回答