我已经尝试解决这个问题 2 小时了,但无法成功
下面附上此查询的响应:
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
现在,我想做的是,对AVERAGE
所有值进行GROUP BY
登录。
想法?
我已经尝试解决这个问题 2 小时了,但无法成功
下面附上此查询的响应:
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
现在,我想做的是,对AVERAGE
所有值进行GROUP BY
登录。
想法?
SELECT
login,
AVG(weekly_gain) AS 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) As l
只需使用查询作为子查询。
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