1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| SQL>
SQL> drop table td;
Table dropped.
SQL>
SQL> create table td (
2 id number,
3 libelle varchar2(6),
4 debit number(8,2),
5 code varchar2(4)
6 );
Table created.
SQL>
SQL> insert into td values (1, 'CSO123', 152.5, 'XXX');
1 row created.
SQL> insert into td values (2, 'CSO123', 485, 'WWA');
1 row created.
SQL> insert into td values (3, 'CSO124', 15.5, 'AZE');
1 row created.
SQL> insert into td values (4, 'CSO124', 489, 'AREC');
1 row created.
SQL> insert into td values (5, 'CSO125', 500, 'AREC');
1 row created.
SQL> commit;
Commit complete.
SQL>
SQL> select id, libelle, debit, code,
2 sum(debit) over (partition by libelle) sum_debit,
3 row_number() over (partition by libelle order by id) rn
4 from td;
ID LIBELL DEBIT CODE SUM_DEBIT RN
---------- ------ ---------- ---- ---------- ----------
1 CSO123 152.5 XXX 637.5 1
2 CSO123 485 WWA 637.5 2
3 CSO124 15.5 AZE 504.5 1
4 CSO124 489 AREC 504.5 2
5 CSO125 500 AREC 500 1
SQL>
SQL> select id, libelle, debit, sum_debit, code
2 from ( select id, libelle, debit, sum_debit, code,
3 min(rn) over (partition by libelle) min_rn,
4 max(rn) over (partition by libelle) max_rn
5 from ( select id, libelle, debit, code,
6 sum(debit) over (partition by libelle) sum_debit,
7 row_number() over (partition by libelle order by id) rn
8 from td)
9 ) where min_rn <> max_rn;
ID LIBELL DEBIT SUM_DEBIT CODE
---------- ------ ---------- ---------- ----
1 CSO123 152.5 637.5 XXX
2 CSO123 485 637.5 WWA
3 CSO124 15.5 504.5 AZE
4 CSO124 489 504.5 AREC
SQL> |
Partager