标签: mysql-error-1055

选择列表包含非聚合列

自从更新 MySQL 我注意到以下查询失败

SELECT u.*, p.name as plan, COUNT(u.id) as totalprojects FROM users u LEFT JOIN plans p ON p.id = access LEFT JOIN maps m ON m.user_id = u.id WHERE u.email = 'john@doe.com'
Run Code Online (Sandbox Code Playgroud)

在没有 GROUP BY 的聚合查询中,SELECT 列表的表达式 #1 包含非聚合列 'kontakt.u.id';这与 sql_mode=only_full_group_by 不兼容

有谁知道如何修复此查询以对错误进行排序?

mysql mysql-error-1055

4
推荐指数
2
解决办法
7553
查看次数

MySQL Group By功能在不同的版本中

以下是一个简单的SQL查询:

SELECT * FROM *table_name*
GROUP BY *column_name*
Run Code Online (Sandbox Code Playgroud)

在我的系统中,我有MySQL 5.5.它工作得非常好.而在我朋友的系统中,他有MySQL 5.7,并且他收到以下错误:

错误1055(42000):SELECT列表的表达式#1不在GROUP BY子句中,并且包含非聚合列'testdb.assetentry.entryId',它在功能上不依赖于GROUP BY子句中的列; 这与sql_mode = only_full_group_by不兼容

很明显,这种情况正在发生,因为版本不同.

但我想知道的是背后的原因.

任何人都可以解释一下.

mysql sql aggregate-functions mysql-error-1055

3
推荐指数
1
解决办法
1140
查看次数

MySQL错误:SELECT列表不在GROUP BY子句中

我的查询有问题,mysql抛出以下错误:

#1055 - Expression #66 of SELECT list is not in GROUP BY clause and 
contains nonaggregated column 's.status' which is not functionally 
dependent on columns in GROUP BY clause; this is incompatible with 
sql_mode=only_full_group_by
Run Code Online (Sandbox Code Playgroud)

查询是:

select   p.*,
pd.*,
m.*,
IF(s.status, s.specials_new_products_price, null) as specials_new_products_price,
IF(s.status, s.specials_new_products_price, p.products_price) as final_price
FROM products p 
LEFT JOIN specials s ON p.products_id = s.products_id  
LEFT JOIN manufacturers m using(manufacturers_id) , 
          products_description pd,
          categories c,
          products_to_categories p2c
WHERE p.products_view = 1  
AND p.products_status = …
Run Code Online (Sandbox Code Playgroud)

mysql group-by mysql-error-1055

1
推荐指数
1
解决办法
1万
查看次数

MySql 5.7 ORDER BY子句不在GROUP BY子句中,并且包含非聚合列

我试图找出而不在my.ini中禁用"only_full_group_by"

这是我的查询:

SELECT 
  p.title,
  COUNT(t.qty) AS total 
FROM
  payments t 
  LEFT JOIN products AS p 
    ON p.id = t.item 
WHERE t.user = 1 
GROUP BY t.item
ORDER BY t.created DESC;
Run Code Online (Sandbox Code Playgroud)

和表格:

支付方式:

id     item   user   created
============================
1      1      1      2017-01-10
2      2      1      2017-01-11
3      3      1      2017-01-12
4      4      1      2017-01-13
5      1      1      2017-01-14
Run Code Online (Sandbox Code Playgroud)

产品介绍:

id     title    created
==========================
1      First     2016-12-10
1      Second    2016-12-11
1      Third     2016-12-12
1      Fourth    2016-12-13
Run Code Online (Sandbox Code Playgroud)

最后的结果看起来应该是谎言:

Name    Total
First   2
Second …
Run Code Online (Sandbox Code Playgroud)

mysql sql group-by mysql-error-1055

1
推荐指数
1
解决办法
6079
查看次数

如何解决 SELECT 列表不在 GROUP BY 子句中且包含非聚合的问题?

我在 MYSQL 5.7 上收到此请求的错误。如何解决这个错误?

#1055 - SELECT 列表的表达式 #3 不在 GROUP BY 子句中,并且包含非聚合列“test.c.customers_group_id”,该列在功能上不依赖于 GROUP BY 子句中的列;这与 sql_mode=only_full_group_by 不兼容

select  SQL_CALC_FOUND_ROWS  c.customers_firstname, 
                             c.customers_lastname, 
                             c.customers_group_id,
                             sum(op.products_quantity * op.final_price) as ordersum 
from customers c,
     orders_products op,
     orders o
where c.customers_id = o.customers_id 
and o.orders_id = op.orders_id 
group by c.customers_firstname, 
         c.customers_lastname 
order by ordersum DESC
Run Code Online (Sandbox Code Playgroud)

mysql mysql-error-1055

0
推荐指数
1
解决办法
3万
查看次数