Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL查询分组依据和订单依据_Sql - Fatal编程技术网

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

我的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 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
。如果您想使用当前版本,您可以通过模式禁用
仅禁用整个组,然后查询将按预期运行。但是,一般来说,您可能希望保持此模式处于打开状态