2017-02-22 59 views
0

我正在嘗試生成池匹配的結果。我在計算一名球員在比賽中贏得的幀數,但是對於那些沒有贏得比賽的球員而言,難以產生結果。如何生成不符合計數條件的記錄與

我讀過,當使用計數和組通過記錄返回0被刪除,但我不確定任何其他方法,我可以使用。

請你可以告訴我怎麼可以在下面改善我的查詢,謝謝:)

select 
    t1.Match_ID, 
    t1.Home_Player_ID, 
    Frames_Won, 
    coalesce(Frames_Lost,0) as Frames_Lost 
from 
    (
    select 
     Match_ID, 
     Home_Player_ID, 
     count(*) as Frames_Won 
    from 
     Match 
    where 
     Home_Player_Win = 1 
    and 
     Match_ID = '56D4FF05-5F33-43FC-A566-2251E790C57F' 
    group by 
     Match_ID, 
     Home_Player_ID 
    ) t1 
left join 
    (
    select 
     Match_ID, 
     Home_Player_ID, 
     count(*) as Frames_Lost 
    from 
     Match 
    where 
     Home_Player_Win = 0 
    and 
     Match_ID = '56D4FF05-5F33-43FC-A566-2251E790C57F' 
    group by 
     Match_ID, 
     Home_Player_ID 
    ) t2 
on t1.Home_Player_ID = t2.Home_Player_ID 

回答

2

我想你錯過了,用戶也沒有贏了,因爲第一子查詢限制任何遊戲記錄,其中home_player_win = 1.

是否有任何理由爲什麼這個查詢不起作用?

SELECT 
Match_ID, 
Home_Player_ID, 
SUM(home_player_win) 
FROM match 
WHERE Match_ID = '56D4FF05-5F33-43FC-A566-2251E790C57F' 
GROUP BY Match_ID, Home_Player_ID; 
+0

總和,當然!返回的結果集正是我所追求的。謝謝。 – Floyd

相關問題