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
因为其他列tc
和tp
是聚合的,不需要包含在分组依据列表中,而room_id
和room_number
不是。
关于mysql - 我的查询显示 heidisql 错误,不知道如何修复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55554097/