MySQL5.7之后sql_mode中ONLY_FULL_GROUP_BY模式默认设置为打开状态。
在所有非聚合列(也就是表中直接取的数据)上加any_value ()包裹
**注意:order by中使用的列也要包裹**
ANY_VALUE()函数对于启用了ONLY_FULL_GROUP_BY模式,使用GROUP BY进行查询时很有用;该函数用于抑制启用ONLY_FULL_GROUP_BY模式时导致的值拒绝;
例子:
SELECT
any_value ( a.id ) AS id,
a.footprint_id AS footprintId,
any_value ( a.footprint_type ) AS footprintType,
any_value ( a.user_id ) AS userId
FROM
info_footprint a
WHERE
a.footprint_type = 3
AND a.user_id = 1
AND a.del_flag = '0'
GROUP BY
footprint_id
ORDER BY
any_value(a.id) DESC
LIMIT 10;