SQL查询分组依据和订单依据
我的sql查询如下SQL查询分组依据和订单依据,sql,Sql,我的sql查询如下 SELECT `speciesname`, sum(`total_species_catch`) as species_catch FROM `species_estimation` GROUP by `speciesid` ORDER by `species_catch` DESC LIMIT 0,10 它在本地主机phpmyadmin中运行良好 在服务器中,它显示错误,如 SELECT list is not in GROUP BY clause and contain
SELECT `speciesname`, sum(`total_species_catch`) as species_catch FROM `species_estimation` GROUP by `speciesid` ORDER by `species_catch` DESC LIMIT 0,10
它在本地主机phpmyadmin中运行良好
在服务器中,它显示错误,如
SELECT list is not in GROUP BY clause and contains nonaggregated column 'fimsul.species_estimation.speciesname' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
请尝试以下操作-可能是您没有在GROUPBY子句中添加
speciesname
SELECT `speciesname`, sum(`total_species_catch`) as species_catch
FROM `species_estimation` GROUP by `speciesname`
ORDER by `species_catch` DESC LIMIT 0,10
这里的快速修复方法是只将
speciesname
包含在groupby
子句中:
SELECT
speciesname,
SUM(total_species_catch) AS species_catch
FROM species_estimation
GROUP BY
speciesname,
speciesid
ORDER BY
species_catch DESC
LIMIT 0,10;
在SELECT
子句中包含speciesid
可能也有意义,以防两个名称恰好相同,并且可以使用id来区分重复项
请注意,当前查询实际上符合ANSI标准,假设speciesid
唯一地确定speciesname
。如果您想使用当前版本,您可以通过模式禁用仅禁用整个组,然后查询将按预期运行。但是,一般来说,您可能希望保持此模式处于打开状态