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
答案 0 :(得分:0)
该错误消息表示您需要将group by子句转换为
GROUP BY hotel_id, room_id, room_number
因为其他列tc
和tp
已汇总,因此无需包含在分组依据列表中,而room_id
和room_number
则没有。