Mysql 本月的Sql查询,以及发送更多帖子的用户
我试图向用户展示更多从本月开始添加到列表中的帖子。但是不起作用Mysql 本月的Sql查询,以及发送更多帖子的用户,mysql,sql,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表数据: INSERT INTO `posts` (`id`, `api_id`, `user_id`, `group_id`, `mess
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);
您应该在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
在大多数SQL方言中,选择不属于分组的任何列都是非法的。(MySQL基于服务器配置允许它,但随后随机从组中的一行传递列值。)在发布问题之前阅读