当前位置:   article > 正文

mysql中group by报错记录以及子查询疑问_mysql group by报错

mysql group by报错

一、group by使用问题记录
问题:使用如下查询

SELECT id,count(*) from stu GROUP BY grade; 报错:1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.stu.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
  • 1

原因:当使用GROUP BY语句时,SELECT列表中的所有列都必须是聚合函数的参数或者是GROUP BY语句中列出的列

二、子查询 sql语句
语句:

SELECT cust_name,cust_state,(SELECT COUNT(*) FROM orders WHERE    orders.cust_id=customers.cust_id) AS orders FROM customers  ORDER BY cust_name;
  • 1

解释:表示对于customers表的每一行都执行一次这个子查询

SELECT COUNT(*) FROM orders WHERE orders.cust_id=customers.cust_id)
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/煮酒与君饮/article/detail/959610
推荐阅读
相关标签
  

闽ICP备14008679号