-1

次の表とデータ、およびルールで期待される出力があります

drop table test_new

create table test_new (id number(9), loc1 number(9), loc2 number(9), percentage number(9));

insert into test_new values (1,1,2,0);
insert into test_new values(2,1,3,10);
insert into test_new values(3,1,4,5);
insert into test_new values(4,1,5,45);
insert into test_new values(5,2,3,0);
insert into test_new values(6,2,4,90);
insert into test_new values(7,2,5,0);
insert into test_new values(8,3,4,0);
insert into test_new values(9,3,5,0);
insert into test_new values(10,4,5,40);
insert into test_new values(11,7,5,0);
insert into test_new values(12,9,4,0);
insert into test_new values(13,10,5,90);
insert into test_new values(14,11,5,70);
insert into test_new values(15,1,15,45);

このフォームが必要ですクエリは次のことを示しています

id  loc1 loc2  percentage
15    1    15       45
2    1    3       10
6    2    4       90
13   10   5       90

これじゃない

id   loc1 loc2  percentage
2    1    3       10
15    1    15      45
6    2    4       90
13   10   5       90

ルール:

  1. id, loc1, loc2, percentageパーセンテージがゼロより大きい場所を示します。
  2. 列のデータの冗長性をloc2削除して、パーセンテージの値が低い行を削除します。
  3. percentage asc列loc1に基づいてデータを並べ替え、グループ化します。
4

1 に答える 1

0

これを試してみてください。

select t1.* from test_new t1
left join test_new t2
on t1.loc2 = t2.loc2 and t1.percentage < t2.percentage
where t1.percentage > 0 and t2.loc2 is null
order by t1.percentage

ただし、コメントに基づいて(結果テーブルではなく、間違っているようです)、これはあなたが期待しているものだと思います:

+----+------+------+------------+
| ID | LOC1 | LOC2 | PERCENTAGE |
+----+------+------+------------+
|  2 |    1 |    3 |         10 |
| 15 |    1 |   15 |         45 |
|  6 |    2 |    4 |         90 |
| 13 |   10 |    5 |         90 |
+----+------+------+------------+
于 2012-12-04T06:28:22.283 に答える