为什么执行count()返回带有回溯的PhpMyAdmin错误

时间:2018-12-22 17:32:17

标签: mysql phpmyadmin

我正在尝试通过PHPMyAdmin 4.8.4执行以下命令:

SELECT *, count(ref_id) AS c FROM `articles_test` group by ref_id order by c desc

这将返回以下错误消息:

enter image description here

此错误回溯跟踪:

  

./ libraries / classes / Display / Results.php#2488中的通知尝试获取   非对象的属性

     

回溯

     

./ libraries / classes / Display / Results.php#2389:   PhpMyAdmin \ Display \ Results-> _ addClass(字符串'data hide',布尔值   false,NULL,字符串``,)   ./libraries/classes/Display/Results.php#3818:   PhpMyAdmin \ Display \ Results-> _ buildNullDisplay(字符串'data hide',   布尔值false,NULL,)./libraries/classes/Display/Results.php#3071:   PhpMyAdmin \ Display \ Results-> _ getDataCellForNonNumericColumns(NULL,   字符串'data hide',NULL,数组,数组,布尔值false,数组,数组,   array,boolean false,array,,NULL,)   ./libraries/classes/Display/Results.php#2695:   PhpMyAdmin \ Display \ Results-> _ getRowValues(,array,integer 24,array,   数组,字符串“ grid_edit click2”,数组,字符串“ SELECT *”,   count(ref_id)AS c FROM articles_test组按ref_id顺序按c   desc',数组,)./libraries/classes/Display/Results.php#4287:   PhpMyAdmin \ Display \ Results-> _ getTableBody(,array,array,array,   布尔值false,)./libraries/classes/Sql.php#1738:   PhpMyAdmin \ Display \ Results-> getTable(,array,array,boolean false,)   ./libraries/classes/Sql.php#2031:   PhpMyAdmin \ Sql-> getHtmlForSqlQueryResultsTable(,字符串   './themes/pmahomme/img/'、NULL,数组,布尔布尔值,字符串'2554',   整数25,NULL,数组)./libraries/classes/Sql.php#2252:   PhpMyAdmin \ Sql-> getQueryResponseForResultsReturned(,array,string   'test',字符串'articles_test',NULL,NULL,,字符串   './themes/pmahomme/img/',字符串'2554',整数25,NULL,NULL,NULL,   NULL,NULL,字符串'SELECT *,count(ref_id)AS c FROM articles_test   按ref_id分组,按c desc',NULL,)。/import.php#736:   PhpMyAdmin \ Sql-> executeQueryAndGetQueryResponse(数组,布尔值false,   字符串'test',字符串'articles_test',NULL,NULL,NULL,NULL,NULL,   NULL,字符串“ tbl_structure.php”,字符串“ ./themes/pmahomme/img/”,   NULL,NULL,NULL,字符串'SELECT *,count(ref_id)AS c FROM   articles_test按ref_id按c desc',NULL,NULL,)分组

我正在运行以下系统:

  

5.7.24-0ubuntu0.16.04.1-Apache / 2.4.18(Ubuntu)Datenbank-Client   版本:libmysql-mysqlnd 5.0.12-dev-20150407-$ Id:   b5c5906d452ec590732a93b051f3827e02749b83 $ PHP   mysqliDokumentation curlDokumentation mbstringDokumentation   PHP版本:7.0.32-0ubuntu0.16.04.1

这是一个错误,还是数据库有问题?没有错误可见,表看起来还可以。

1 个答案:

答案 0 :(得分:1)

您正在使用的MySQL版本是什么。查询

SELECT *, count(ref_id) AS c 
FROM `articles_test` 
group by ref_id order by c desc
由于默认的sql_mode only_full_group_by,

将无法在MySQL 5.7和更高版本的默认设置中运行。问题是您将所有列符号(*)与聚合函数混合在一起。较早的MySQL版本允许此(错误)查询,但默认情况下MySQL 5.7更为严格。

如果您要列出article_test中的所有行,并为每个ref_id计数(对于相同的ref_id重复相同的值),请使用子查询:

SELECT a.*, count(ref_id) AS c 
FROM articles_test a
  JOIN (
    SELECT at.ref_id, count(*) as refid_count
    FROM articles_test at
    GROUP BY at.ref_id
  ) q as q.ref_id=a.ref_id