2017-11-24 13 views
-1

を制限を追加します。 creatorタグを見ると、それはKrの領域しかないので、私はそれを取り除きたいです。 Am領域しか持たないので、PartinGと同じことです。は、私は、このSQLクエリを持つSQLクエリに

+-------------+-----------+--------+ 
| tag   | game_race | region | 
+-------------+-----------+--------+ 
| Leenock  | Z   | AM  | 
| Leenock  | Z   | EU  | 
| Leenock  | Z   | AM  | 
| Leenock  | Z   | AM  | 
| Leenock  | Z   | EU  | 
| Leenock  | Z   | KR  | 
| Creator  | P   | KR  | 
| Creator  | P   | KR  | 
| Life  | Z   | AM  | 
| Life  | Z   | EU  | 
| Life  | Z   | KR  | 
| Life  | Z   | KR  | 
| Life  | Z   | AM  | 
| Life  | Z   | KR  | 
| Life  | Z   | KR  | 
| Life  | Z   | EU  | 
| Life  | Z   | EU  | 
| DongRaeGu | Z   | KR  | 
| DongRaeGu | Z   | KR  | 
| DongRaeGu | Z   | KR  | 
| DongRaeGu | Z   | KR  | 
| DongRaeGu | Z   | EU  | 
| DongRaeGu | Z   | AM  | 
| DongRaeGu | Z   | AM  | 
| DongRaeGu | Z   | AM  | 
| PartinG  | P   | AM  | 
| TaeJa  | T   | KR  | 
| TaeJa  | T   | EU  | 
| TaeJa  | T   | AM  | 
| TaeJa  | T   | KR  | 
| TaeJa  | T   | EU  | 
| TaeJa  | T   | KR  | 
| TaeJa  | T   | EU  | 
| TaeJa  | T   | KR  | 
| TaeJa  | T   | EU  | 
| TaeJa  | T   | KR  | 
| TaeJa  | T   | EU  | 
| TaeJa  | T   | KR  | 
| TaeJa  | T   | KR  | 
| TaeJa  | T   | KR  | 
| TaeJa  | T   | KR  | 
| TaeJa  | T   | KR  | 

これはうまくいくと思っていましたが、重複が発生しました。

SELECT players.player_id, players.tag, players.game_race, 
    earnings.tournament, earnings.player, earnings.position, 
    tournaments.tournament_id, tournaments.region 
FROM players 
JOIN earnings ON players.player_id = earnings.player 
JOIN (SELECT player FROM earnings 
    where position = 1 group by player having count(player) > 2) 
    as DupPlayer on earnings.player=DupPlayer.player 
JOIN (SELECT region FROM tournaments 
    group by region having count(region) > 2) 
    as DupPlayer1 on region=DupPlayer1.region 
JOIN tournaments ON earnings.tournament = tournaments.tournament_id 
where earnings.position = 1 and tournaments.region is not NULL 
ORDER BY players.player_id; 

の提案をしようとしています。これは動作していないようです。それはPartingを後に残し、SjoWはすべてEUを持っています。

> SELECT players.tag, players.game_race, tournaments.region 
    -> FROM players 
    -> JOIN earnings ON players.player_id = earnings.player 
    -> JOIN (SELECT player FROM earnings 
    ->  where position = 1 group by player having count(player) > 2) 
    ->  as DupPlayer on earnings.player=DupPlayer.player 
    -> JOIN tournaments ON earnings.tournament = tournaments.tournament_id 
    ->  and tournaments.region in ('AM', 'EU', 'KR') 
    -> where earnings.position = 1 and tournaments.region is not NULL 
    -> and players.tag in (
    -> SELECT players.tag 
    -> FROM players 
    -> JOIN earnings ON players.player_id = earnings.player 
    -> JOIN (SELECT player FROM earnings 
    ->  where position = 1 group by player having count(player) > 2) 
    ->  as DupPlayer on earnings.player=DupPlayer.player 
    -> JOIN tournaments ON earnings.tournament = tournaments.tournament_id 
    ->  and tournaments.region in ('AM', 'EU', 'KR') 
    ->  group by players.tag 
    ->  having count(distinct tournaments.region) = 3 
    ->) 
    -> ORDER BY players.player_id; 
+------------+-----------+--------+ 
| tag  | game_race | region | 
+------------+-----------+--------+ 
| Leenock | Z   | AM  | 
| Leenock | Z   | AM  | 
| Leenock | Z   | AM  | 
| Leenock | Z   | EU  | 
| Leenock | Z   | EU  | 
| Leenock | Z   | KR  | 
| Life  | Z   | AM  | 
| Life  | Z   | AM  | 
| Life  | Z   | EU  | 
| Life  | Z   | EU  | 
| Life  | Z   | KR  | 
| Life  | Z   | KR  | 
| Life  | Z   | KR  | 
| Life  | Z   | KR  | 
| Life  | Z   | EU  | 
| DongRaeGu | Z   | KR  | 
| DongRaeGu | Z   | KR  | 
| DongRaeGu | Z   | AM  | 
| DongRaeGu | Z   | AM  | 
| DongRaeGu | Z   | AM  | 
| DongRaeGu | Z   | KR  | 
| DongRaeGu | Z   | EU  | 
| DongRaeGu | Z   | KR  | 
| PartinG | P   | AM  | 
| TaeJa  | T   | KR  | 
| TaeJa  | T   | AM  | 
| TaeJa  | T   | KR  | 
| TaeJa  | T   | EU  | 
| TaeJa  | T   | KR  | 
| TaeJa  | T   | KR  | 
| TaeJa  | T   | EU  | 
| TaeJa  | T   | EU  | 
| TaeJa  | T   | EU  | 
| TaeJa  | T   | KR  | 
| TaeJa  | T   | EU  | 
| TaeJa  | T   | KR  | 
| TaeJa  | T   | KR  | 
| TaeJa  | T   | KR  | 
| TaeJa  | T   | KR  | 
| TaeJa  | T   | KR  | 
| viOLet  | Z   | AM  | 
| viOLet  | Z   | AM  | 
| viOLet  | Z   | EU  | 
| HerO  | P   | AM  | 
| HerO  | P   | AM  | 
| HerO  | P   | EU  | 
| HerO  | P   | EU  | 
| HerO  | P   | AM  | 
| SjoW  | T   | EU  | 
| SjoW  | T   | EU  | 
| SjoW  | T   | EU  | 
| SjoW  | T   | EU  | 
| SjoW  | T   | EU  | 

答えて

0

あなたはすべての3領域にのみ結果が必要な場合は「AM」、「EU」、「KR」 あなたはこの結果をフィルタリングして、カウントを持つすべてのサブクエリを使用しているtahtタグをチェックする必要があります

JOIN (SELECT region FROM tournaments 
    group by region having count(region) > 2) 

あなたは右の一般的な考え方が、間違ったディテールを持っています(個別の領域)3

SELECT players.tag, players.game_race, tournaments.region 
FROM players 
JOIN earnings ON players.player_id = earnings.player 
JOIN (SELECT player FROM earnings 
    where position = 1 group by player having count(player) > 2) 
    as DupPlayer on earnings.player=DupPlayer.player 
JOIN tournaments ON earnings.tournament = tournaments.tournament_id 
    and tournaments.region in ('AM', 'EU', 'KR') 
where earnings.position = 1 and tournaments.region is not NULL 
and players.tag in ( 
    SELECT players.tag 
    FROM players 
    JOIN earnings ON players.player_id = earnings.player 
    JOIN (SELECT player FROM earnings 
     where position = 1 group by player having count(player) > 2) 
     as DupPlayer on earnings.player=DupPlayer.player 
    JOIN tournaments ON earnings.tournament = tournaments.tournament_id 
     and tournaments.region in ('AM', 'EU', 'KR') 
     group by players.tag 
     having count(distinct tournaments.region) = 3 
) 
ORDER BY players.player_i 
+0

これは機能していないようです。それはPartingを後に残し、SjoWはすべてEUを持っています。 – noobprogrammer1987

0

を=これは、追加した一部のように見えます。サブクエリを変更して、3つのリージョンからプレイヤーだけを選択します。

関連する問題