gpt4 book ai didi

MySQL 嵌套优化

转载 作者:行者123 更新时间:2023-11-29 08:32:29 25 4
gpt4 key购买 nike

我已经尝试解决这个问题两个小时了,但没有成功

下面附上对此查询的响应:

SELECT login, SUM(gain) AS weekly_gain
FROM gt_history
WHERE is_closed = 1 AND (cmd = 0 OR cmd = 1)
GROUP BY WEEK(close_time), login

现在,我想做的是,对所有值进行平均GROUP BY登录。

想法?

result from first query

最佳答案

只需使用您的查询作为子查询。

SELECT login, AVG(weekly_gain) FROM
(SELECT login, SUM(gain) AS weekly_gain
FROM gt_history
WHERE is_closed = 1 AND (cmd = 0 OR cmd = 1)
GROUP BY WEEK(close_time), login)
GROUP BY login

关于MySQL 嵌套优化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16212030/

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