【问题标题】:MySQL Error #1055 When getting"leaderboard" statsMySQL 错误 #1055 获取“排行榜”统计信息时
【发布时间】:2021-04-21 16:00:37
【问题描述】:
SELECT unitidentifier, unitdiscordid, count(unitdiscordid) 
FROM warnings 
GROUP BY unitdiscordid 
ORDER BY count(unitdiscordid) DESC 
LIMIT 1

这是我正在运行的查询,我收到以下错误:

#1055 - SELECT 列表的表达式 #1 不在 GROUP BY 子句中,并且包含非聚合列“libertyr_cad.warnings.unitidentifier” 它在功能上不依赖于 GROUP BY 子句中的列; 这与 sql_mode=only_full_group_by 不兼容

我尝试更改查询但仍然没有成功,我知道可以通过编辑 sql_mode 来解决问题,但如果可能的话,我希望不这样做就找到解决方法。

【问题讨论】:

标签: mysql


【解决方案1】:

当您执行GROUP BY 时,您正在执行聚合并且您的个人记录级字段不一定可访问。您需要将您使用的字段添加到 GROUP BY 中,以确保将它们考虑到聚合中:

SELECT unitidentifier, unitdiscordid, count(unitdiscordid) 
FROM warnings 
GROUP BY unitidentifier, unitdiscordid 
ORDER BY count(unitdiscordid) DESC 
LIMIT 1

【讨论】:

    猜你喜欢
    • 2012-03-11
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 2014-02-11
    • 1970-01-01
    • 1970-01-01
    • 2015-01-29
    • 2023-04-09
    相关资源
    最近更新 更多