gpt4 book ai didi

mysql - 如何让这个 MySQL 查询在 MySQL 4.1.15 上运行?

转载 作者:行者123 更新时间:2023-11-29 14:30:00 26 4
gpt4 key购买 nike

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

#1140 - Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause

顺便说一句,升级客户端 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")

最佳答案

无法测试,但鉴于错误,似乎需要进行分组..

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

关于mysql - 如何让这个 MySQL 查询在 MySQL 4.1.15 上运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10179219/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com