0

私はoracle 10g EEデータベースを使用しています.1つのテーブルmytableがあり、2つの列があり、データは次のとおりです:

:2番目の列の同じ値に基づいてデータを見つけたいのですが、最初の列に同じ値または異なる値が存在するかどうかは関係ありません。

10A, B and Cとについて 3 回繰り返されます。these 3 are required output

同様にand20に対して 2 回繰り返され、これらも必要な出力です。CD

   column1             column2
--------------     ---------------

     A                  10 //required
     A                  10 //required        
     B                  10 //required
     C                  20//required
     D                  20//required
     E                  30--------not required as 30 is only here and not duplicated
     F                  40--------not required as 40 is only here and not duplicated

次の出力が必要です。つまり、2 列目に同じ値があり、1 列目に同じ値または異なる値があります。

   column1             column2
--------------     ---------------

     A                  10         
     A                  10           
     B                  10
     C                  20
     D                  20
4

3 に答える 3

3
SELECT column1,
       column2
  FROM <table> t1
 WHERE column2 IN (SELECT column2
                     FROM <table> t2
                    GROUP BY column2
                    HAVING count(*) > 1);
于 2012-04-18T09:55:59.247 に答える
3

欲しいらしい

SELECT *
  FROM table_name t1
 WHERE column2 IN( SELECT column2
                     FROM table_name t2
                    GROUP BY column2
                   HAVING COUNT(*) > 1 )

これはあなたのサンプルデータで動作するようです

SQL> with table_name as (
  2    select 'A' column1, 10 column2 from dual union all
  3    select 'A', 10 from dual union all
  4    select 'B', 10 from dual union all
  5    select 'C', 20 from dual union all
  6    select 'D', 30 from dual)
  7  SELECT *
  8    FROM table_name t1
  9   WHERE column2 IN( SELECT column2
 10                       FROM table_name t2
 11                      GROUP BY column2
 12                     HAVING COUNT(*) > 1 );

C    COLUMN2
- ----------
B         10
A         10
A         10
于 2012-04-18T09:55:14.230 に答える
0

select * from table where column2 in ( count(*)>1 を持つ coulmn2 によってテーブル グループから column2 を選択);

あなたのために働くはずです。

ありがとうございます

于 2012-04-18T10:08:48.297 に答える