2016-08-04 3 views
0
From this table 

--------------------------- 
| id  | country  | 
--------------------------- 
| 1   | India  | 
--------------------------- 
| 2   | India  | 
--------------------------- 
| 2   | India  | 
--------------------------- 
| 3   | India  | 
--------------------------- 
| 1   | U.S.  | 
--------------------------- 
| 1   | U.S.  | 
--------------------------- 
| 2   | U.K.  | 
--------------------------- 
| 2   | U.K.  | 
--------------------------- 
| 2   | U.K.  | 
--------------------------- 

i need to achieve this result 

-------------- 
| id  | 
-------------- 
| 1   | 
-------------- 
| 2   | 
-------------- 

Scenario: I need to get the common id for country 'India' as well as non 'India' 

Please, help me to achieve this.
+0

あなたの式は、 "共通" 何のためにあるのですが、インド= 2のための共通ID、非インド人の共通IDも2です。なぜあなたのリストに1が含まれていますか? – SIDU

答えて

0

はここでそれを行うための一つの方法です

SELECT id 
FROM mytable 
WHERE country = 'India' 
     AND id IN (SELECT id 
        FROM mytable 
        WHERE country <> 'India') 
0

IN使用してみてください:上記のデータによると、

select id 
from 
    (
    select id 
    from CountryIDs 
    group by id, case when country = 'India' then 1 else 0 end 
    ) ids 
group by id 
having COUNT(*)=2 
関連する問題