-1

1我想在一个查询 中显示具有最高等级字符的帐户和他们的时间总和表帐户的统计信息。

我有两个包含以下数据的表:

表:账户:

Id| Username |Stats
1 | player1  |1
2 | goodman  |1
3 | goodbat  |1
4 | ashasdd  |0

表:字符:

Guid| Account | Name | Rank | Time |
213 |    1    | fres |  2   |  51  |
214 |    2    | sdg2 |  3   |  12  |
215 |    2    | fgax |  4   |  99  |
216 |    3    | zFvx |  8   |  23  |
217 |    3    | Sgzs |  2   |  13  |

输出/结果:(显示具有最高等级字符及其时间总和的帐户字符)

Username : player1 | Name: fres(Rank:2) |Time : 51
Username : goodman | Name: fgax(Rank:4) |Time : 111
Username : goodbat | Name: zFvx(Rank:8) |Time : 36

什么是简单的 MySQL 查询?

我的错误查询:(不工作)

SELECT a.username, a.email, c.name, SUM(c.time), c.rank
FROM `auth`.`account` a, `characters`.`characters` c
WHERE a.id=c.account
ORDER BY c.rank ASC
LIMIT 20
4

2 回答 2

1

应该够了。。我想。

SELECT c.Account, a.Username, c.Name, MAX(c.Rank) as maxrank, SUM(c.TIME) as sumtime  FROM characters c LEFT JOIN Accounts a ON a.Id=c.Account GROUP By c.Account;
于 2012-11-21T18:15:25.223 回答
0

像这样的东西可能会起作用

SELECT username, name, d.rank, c.Time
FROM (

    SELECT a.Username, b.account, MAX( b.Rank ) AS rank, SUM( b.Time ) AS TIME
    FROM accounts a
    INNER JOIN characters b ON a.ID = b.Account
    WHERE a.stats =1
    GROUP BY a.Username
) AS c
JOIN characters d ON d.account = c.account
AND d.rank = c.rank
ORDER BY rank

不知道怎么做,从那以后你可能会得到错误的名字,那是没有注册的最高排名。

于 2012-11-21T18:38:12.760 回答