0
我想結合約3 MySQL查詢到一個,但一些複雜。 (下面是我的測試querys和表DATAS例子)結合兩個查詢,總和最大值列
表1:佔
id | account | email | refer
11 | aasdasd | [email protected] | 0
12 | gasd | [email protected] | 11
13 | xcsxs | [email protected] | 11
14 | cbasd | [email protected] | 11
15 | asdv | [email protected] | 11
16 | sdfgx | [email protected] | 8
...
表2:字符
guid |account| name | rank | time
561 | 11 | asda | 945 | 12
562 | 11 | asda | 746 | 19
563 | 11 | asda | 452 | 1
564 | 12 | asda | 123 | 15
565 | 12 | asda | 456 | 18
566 | 13 | asda | 123 | 6
567 | 13 | asda | 789 | 18
568 | 13 | asda | 123 | 17
569 | 15 | asda | 456 | 13
570 | 16 | asda | 123 | 15
571 | 17 | asda | 456 | 16
...
我測試過的查詢小號:
SELECT id FROM accounts WHERE refer='11'
識別帳戶是具有值「11」 和第二查詢指示,總結TOTALTIME,其中被具有值11是指帳戶字符:
SELECT a.account, a.email, SUM(c.time) , c.rank
FROM accounts a, characters c
WHERE a.id=c.account
ORDER BY MAX(c.rank) DESC
請告訴我我想要:
我想結合上面兩個查詢兩個,並得到如下結果:
排名列是從帳戶和總時間的字符的最高級別是所有總和該帳戶的字符時間
Account | Email | Rank | TotalTime
gasd |[email protected] | 456 | 33
xcsxs |[email protected] | 789 | 41
cbasd |[email protected] | 0 | 0
asdv |[email protected] | 456 | 13
第二個查詢與SUM我認爲有問題,我現在添加它。
看看我的編輯答案 –
組缺...感謝它的工作;)....'編輯: '快速回答記錄:D謝謝;) – Root125