Home » SQL & PL/SQL » SQL & PL/SQL » filtering in a table by ignoring the records those are unnecessary anymore (oracle sql developer 4.1.3.20)
filtering in a table by ignoring the records those are unnecessary anymore [message #648317] |
Sat, 20 February 2016 07:20 |
|
gujarati
Messages: 2 Registered: February 2016
|
Junior Member |
|
|
Hello,
I have a table including CONTRACT_ID, ADDENDUM_ID and PAYMENT_MONTH (payment dates of a yearly contract).
Everytime an update occurs for any reason in the system:
1- ADDENDUM_ID udates as +1
2- PAYMENT_MONTH records are duplicated for the remaining months
In attached file I tried to explain in detail using an example (a contract with 3 updates).
The question is how to write a query to get a summary table ignoring the duplicated but unnecessary records because of a new update on addendum column.
Please note that there are thousands of contracts in the original table, while the example contains only one.
Thanks..
[mod-edit: image inserted into message body by bb]
-
Attachment: example.png
(Size: 33.07KB, Downloaded 1244 times)
[Updated on: Sat, 20 February 2016 12:57] by Moderator Report message to a moderator
|
|
|
|
|
|
|
Re: filtering in a table by ignoring the records those are unnecessary anymore [message #648324 is a reply to message #648323] |
Sat, 20 February 2016 11:13 |
|
live4learn
Messages: 41 Registered: September 2013 Location: Bangalore, India
|
Member |
|
|
create table org_t (c_id number,ad_id number,p_m number)
insert all
into org_t values(155,1,1)
into org_t values(155,1,2)
into org_t values(155,1,3)
into org_t values(155,1,4)
into org_t values(155,1,5)
into org_t values(155,1,6)
into org_t values(155,1,7)
into org_t values(155,1,
into org_t values(155,1,9)
into org_t values(155,1,10)
into org_t values(155,1,11)
into org_t values(155,1,12)
into org_t values(155,2,5)
into org_t values(155,2,6)
into org_t values(155,2,7)
into org_t values(155,2,
into org_t values(155,2,9)
into org_t values(155,2,10)
into org_t values(155,2,11)
into org_t values(155,2,12)
into org_t values(155,3,10)
into org_t values(155,3,11)
into org_t values(155,3,12)
select * from dual
insert into org_t(c_id,ad_id,p_m)
select c_id+1,ad_id,p_m from org_t
commit;
SQL> select * from (
2 select c_id ,max(ad_id),p_m from org_t group by c_id,p_m
3 ) order by 1
4 ;
C_ID MAX(AD_ID) P_M
---------- ---------- ----------
155 1 1
155 1 2
155 1 3
155 1 4
155 2 5
155 2 6
155 2 7
155 2 8
155 2 9
155 3 10
155 3 11
155 3 12
156 1 1
156 1 2
156 1 3
156 1 4
156 2 5
156 2 6
156 2 7
156 2 8
C_ID MAX(AD_ID) P_M
---------- ---------- ----------
156 2 9
156 3 10
156 3 11
156 3 12
24 rows selected
SQL>
|
|
|
|
Goto Forum:
Current Time: Fri Apr 26 06:05:24 CDT 2024
|