我们如何在具有GROUP BY子句的查询中选择非聚合列,而GROUP BY子句在功能上不依赖于GROUP BY子句中的列?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了我们如何在具有GROUP BY子句的查询中选择非聚合列,而GROUP BY子句在功能上不依赖于GROUP BY子句中的列?相关的知识,希望对你有一定的参考价值。
我的SQL
SELECT
`tbl_order`.`order_id`
FROM `tbl_order`
LEFT JOIN `tbl_rooms` ON `tbl_order`.`room_name` = `tbl_rooms`.`room_id`
LEFT JOIN `tbl_orderdetails` ON `tbl_order`.`order_key` = `tbl_orderdetails`.`orderdetail_orderkey`
LEFT JOIN `tbl_guestcatlang` ON `tbl_order`.`order_product_type`=`tbl_guestcatlang`.`guestcatlang_guestcat_id`
and `tbl_guestcatlang`.`guestcatlang_lang_id`="en"
JOIN `tbl_sitesettings` ON `tbl_order`.`order_setting_id` = `tbl_sitesettings`.`setting_id`
WHERE
(
(
tbl_sitesettings.delayedBrekfast = 1 AND
`tbl_order`.`order_product_type` = "BREAKFAST" AND
(
`tbl_order`.`order_required_time` > "2018-02-28 18:30:00" AND
`tbl_order`.`order_required_time` < "2018-03-01 18:29:59" AND
tbl_sitesettings.delayTime - (unix_timestamp(convert_tz(now(),("UTC"), tbl_sitesettings.timeZone))-unix_timestamp()) < "26100"
)
) OR
(
`tbl_sitesettings`.`delayedBrekfast` != 1 OR
`tbl_order`.`order_status` = "Complete" OR
tbl_order.order_product_type != "BREAKFAST"
)
) AND
`tbl_order`.`order_status` IN('Open') AND
`tbl_order`.`order_product_type` IN('BREAKFAST', 'Room Service', 'AMENITIES', 'GIFT SHOP', 'Internet Plan', 'Device Management',
'System Message', '70', '69', '67', '68', '75', '76', '77', '78',
'93', '94', '95', '97', '98', '101', '102', '103', '104', '105',
'106', '107', '108', '109', '110', '111', '112', '113', '114', '115',
'116', '117', '118', '119', '120', '121', '122', '123', '124', '127',
'128', '135') AND
`tbl_order`.`order_product_type` != 'Recomended Product' AND
`tbl_order`.`order_setting_id` = '7'
GROUP BY `tbl_order`.`order_key`
ORDER BY `tbl_order`.`ordered_time` DESC
这是错误消息
SELECT列表的表达式#1不在GROUP BY子句中,并且包含非聚合列'ebdb_production.tbl_order.order_id',它在功能上不依赖于GROUP BY子句中的列;这与sql_mode = only_full_group_by不兼容
有什么办法吗:(
答案
尝试执行以下查询。这将取消对此类的限制。
SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
以上是关于我们如何在具有GROUP BY子句的查询中选择非聚合列,而GROUP BY子句在功能上不依赖于GROUP BY子句中的列?的主要内容,如果未能解决你的问题,请参考以下文章
选择的字段不包含在 GROUP BY 子句中,那么这个 Access 查询如何成功运行?