以下查询适用于MySql 5,但我的客户端有MySql 4.1.15,此查询会出现以下错误:
#1140 - 将GROUP列(MIN(),MAX(),COUNT(),...)混合为no 如果没有GROUP BY子句
,GROUP列是非法的
升级客户端MySql版本不是BTW的选项。有人可以帮我改写这个以使用旧版本的MySql吗?
SELECT
Sum( room_rev + room_rev_future ) as weekly_room_rev,
Sum( (`food_rev`) + (`beverage_rev`)) as weekly_catering_rev,
(SELECT min_sales_persons
FROM bdp_hotel_min WHERE
bdp_hotel_min.hotel_num = bdp_scorecard.hotel_num
AND UNIX_TIMESTAMP(bdp_hotel_min.`min_override_week`)
< UNIX_TIMESTAMP("2011-12-02 23:59:59")
ORDER BY bdp_hotel_min.`min_override_week` DESC LIMIT 1 ) as override_persons,
min_sales_persons
FROM bdp_scorecard JOIN locations ON bdp_scorecard.hotel_num = locations.hotel_num
WHERE bdp_scorecard.hotel_num =837 AND bdp_scorecard.hotel_num = 837
AND UNIX_TIMESTAMP(bdp_scorecard.`created_date`) >= UNIX_TIMESTAMP("2011-11-26")
AND UNIX_TIMESTAMP(bdp_scorecard.`created_date`) < UNIX_TIMESTAMP("2011-12-02 23:59:59")
答案 0 :(得分:1)
无法测试,但看起来像是错误的组合。
SELECT
Sum( room_rev + room_rev_future ) as weekly_room_rev,
Sum( (`food_rev`) + (`beverage_rev`)) as weekly_catering_rev,
(SELECT min_sales_persons
FROM bdp_hotel_min WHERE
bdp_hotel_min.hotel_num = bdp_scorecard.hotel_num
AND UNIX_TIMESTAMP(bdp_hotel_min.`min_override_week`)
< UNIX_TIMESTAMP("2011-12-02 23:59:59")
ORDER BY bdp_hotel_min.`min_override_week` DESC LIMIT 1 ) as override_persons,
min_sales_persons
FROM bdp_scorecard JOIN locations ON bdp_scorecard.hotel_num = locations.hotel_num
WHERE bdp_scorecard.hotel_num =837 AND bdp_scorecard.hotel_num = 837
AND UNIX_TIMESTAMP(bdp_scorecard.`created_date`) >= UNIX_TIMESTAMP("2011-11-26")
AND UNIX_TIMESTAMP(bdp_scorecard.`created_date`) < UNIX_TIMESTAMP("2011-12-02 23:59:59")
GROUP BY override_persons, min_sales_persons