0

我已经尝试解决这个问题 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登录。

想法?

第一次查询的结果

4

2 回答 2

1
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
于 2013-04-25T10:17:50.633 回答
1

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

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
于 2013-04-25T10:46:33.237 回答