使用only_full_group_by
发出mysql新版本我需要使用Group by(col_id)和order by(date)来获取表值 我的代码在mysql中如下:
SELECT COUNT(created_date) AS `Rows` , ANY_VALUE(id)
FROM `table` where `my_id` = 1 AND `status` = '0'
GROUP BY `id`
ORDER BY `created_date` DESC
我收到错误如下
SQLSTATE [42000]:语法错误或访问冲突:1055 ORDER BY子句的表达式#1不在GROUP BY子句中,并且包含非聚合列'database.table.created_date',它在功能上不依赖于GROUP BY子句中的列;这与sql_mode = only_full_group_by
不兼容
有人说解决方案吗?
提前致谢...
答案 0 :(得分:0)
使用“仅完整分组依据”时,order by
不能是任意列。 <{1}}在 order by
之后解析,因此只允许聚合密钥和聚合列。
您可以使用:
group by
如果我不得不猜测,你实际上想要SELECT COUNT(created_date) AS `Rows`, ANY_VALUE(id)
FROM `table`
WHERE `my_id` = 1 AND `status` = '0'
GROUP BY `id`
ORDER BY ANY_VALUE(`created_date`) DESC;
:
MAX()