我的查询显示heidisql错误,不知道如何解决

时间:2019-04-06 22:42:11

标签: mysql sql heidisql

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

1 个答案:

答案 0 :(得分:0)

该错误消息表示您需要将group by子句转换为

GROUP BY hotel_id, room_id, room_number

因为其他列tctp已汇总,因此无需包含在分组依据列表中,而room_idroom_number则没有。