我们如何在具有GROUP BY子句的查询中选择非聚合列,而GROUP BY子句在功能上不依赖于GROUP BY子句中的列?

时间:2018-03-01 07:33:34

标签: mysql 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子句中并且包含   nonaggregated列'ebdb_production.tbl_order.order_id'不是   功能上依赖于GROUP BY子句中的列;这是   与sql_mode = only_full_group_by

不兼容

任何解决方案??? :(

1 个答案:

答案 0 :(得分:1)

尝试执行以下查询。这将取消对此的限制。

.data-sorted