gpt4 book ai didi

mysql - 我的查询显示 heidisql 错误,不知道如何修复

转载 作者:行者123 更新时间:2023-11-29 16:07:57 31 4
gpt4 key购买 nike

SQL 错误 (1055):SELECT 列表的表达式 #2 不在 GROUP BY 子句中,并且包含非聚合列“a.room id”,该列在功能上不依赖于 GROUP BY 子句中的列;这与 sql_mode=only_full_group_by 不兼容

SELECT hotel_id,room_id,room_number,MAX(a.tc) AS "Count",MAX(tp) AS   "MostProfit" FROM
(SELECT hotel_id,rooms.room_id,room_number,COUNT(rooms.room_id) AS "tc",SUM(room_price) AS "tp" FROM rooms JOIN bookings
ON rooms.room_id = bookings.room_id
GROUP BY rooms.room_id) a GROUP BY hotel_id

trying to get the rooms of hotels that got the most profit in a query

最佳答案

错误消息意味着您需要将 group by 子句转换为

GROUP BY hotel_id, room_id, room_number

因为其他列tctp是聚合的,不需要包含在分组依据列表中,而room_idroom_number 不是。

关于mysql - 我的查询显示 heidisql 错误,不知道如何修复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55554097/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com