SELECT DISTINCT d.driver_id FROM tms_one_transport_order ot INNER JOIN tms_driver d ON d.driver_id = ot.driver_id INNER JOIN tms_one_order o ON ot.order_id = o.order_id where o.order_id = 1409 ORDER BY CASE WHEN (o.start_region = ot.start_region AND o.end_region = ot.end_region) THEN o.order_type WHEN (o.start_region = ot.end_region AND o.end_region = ot.start_region) THEN o.order_type END LIMIT 0, 1000 Error Code: 3065. Expression #1 of ORDER BY clause is not in SELECT list, references column 'huanhai_pre2.o.start_region' which is not in SELECT list; this is incompatible with DISTINCT 0.000 sec 为什么数据库里有的字段,报找不到
时间: 2024-04-17 16:23:40 浏览: 177
这个错误是由于在ORDER BY子句中引用了不在SELECT列表中的列所导致的。在你的查询中,你使用了DISTINCT关键字来返回唯一的driver_id,但是在ORDER BY子句中引用了o.start_region列,该列不在SELECT列表中,因此出现了错误。
要解决这个问题,你可以将o.start_region列添加到SELECT列表中,或者从ORDER BY子句中移除该列。以下是修改后的查询:
SELECT DISTINCT d.driver_id, o.start_region
FROM tms_one_transport_order ot
INNER JOIN tms_driver d ON d.driver_id = ot.driver_id
INNER JOIN tms_one_order o ON ot.order_id = o.order_id
WHERE o.order_id = 1409
ORDER BY
CASE
WHEN (o.start_region = ot.start_region AND o.end_region = ot.end_region) THEN o.order_type
WHEN (o.start_region = ot.end_region AND o.end_region = ot.start_region) THEN o.order_type
END
LIMIT 0, 1000
这样修改后,查询将返回唯一的driver_id和o.start_region,并且ORDER BY子句中的列与SELECT列表中的列一致,不会再出现错误。
阅读全文