小编kur*_*ama的帖子

如何解决"ORDER BY子句不在SELECT列表中"导致MySQL 5.7使用SELECT DISTINCT和ORDER BY

我安装了新的Ubuntu,我的代码遇到了MySQL问题.

( ! ) Warning: PDOStatement::execute(): SQLSTATE[HY000]: General error: 3065 
Expression #2 of ORDER BY clause is not in SELECT list, references column 'clicshopping_test_ui.p.products_date_added' which is not in SELECT list; this is incompatible with DISTINCT 
in /home/www//boutique/includes/OM/DbStatement.php on line 97s
Run Code Online (Sandbox Code Playgroud)

似乎MySQL 5.7不允许这样的请求:

select .... distinct with  order by rand(), p.products_date_added DESC
Run Code Online (Sandbox Code Playgroud)

如果我使用它,它的工作原理:

select distinct .... with  order by rand(), 
Run Code Online (Sandbox Code Playgroud)

如何解决这种情况?

我在PHP中的SQL请求

 $Qproduct = $OSCOM_PDO->prepare('select distinct p.products_id,
            p.products_price
            from :table_products p left join :table_specials s on p.products_id = s.products_id
            where products_status …
Run Code Online (Sandbox Code Playgroud)

php mysql

20
推荐指数
5
解决办法
2万
查看次数

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万
查看次数

如何解决 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万
查看次数

标签 统计

mysql ×3

mysql-error-1055 ×2

group-by ×1

php ×1