mysql的group by 直接上sql select id,name,sum(score),sum(money) from table_A 假如说有3条数据 id name score money 1 one 3 10 2 two 5 20 3 thire 7 30 上面的语句不报错?为什么? 按照道理来说应该加入group by 才对的。 求大神们的解释
------解决方案-------------------- 简单地说,不是标准的SQL语句 mysql help: MySQL extends the use of GROUP BY so that you can use non-aggregated columns or calculations in the SELECT list that do not appear in the GROUP BY clause. You can use this feature to get better performance by avoiding unnecessary column sorting and grouping. For example, you do not need to group on customer.name in the following query: SELECT order.custid, customer.name, MAX(payments) FROM order,customer WHERE order.custid = customer.custid GROUP BY order.custid;
In standard SQL, you would have to add customer.name to the GROUP BY clause. In MySQL, the name is redundant.