0

以下查询适用于 MySql 5,但我的客户端具有 MySql 4.1.15,并且此查询因以下错误而窒息:

#1140 - 如果没有 GROUP BY 子句,混合没有 GROUP 列的 GROUP 列 (MIN(),MAX(),COUNT(),...) 是非法的

顺便说一句,升级客户端 MySql 版本不是一个选项。有人可以帮我重写它以在旧版本的 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") 
4

1 回答 1

1

无法测试,但考虑到错误似乎需要 group by

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
于 2012-04-16T18:08:48.590 回答