oracle - Get records where multiple rows are equal value sql server -
i have sql schema below:
ano | code |type | date1 | ex_date|rd_date |cps | tax ______|_______| _____|______ |_ ______|_______ |____|__________ b1 | | t |4/1/2014|3/2/2012|4/2/2010| 99 | 1 b1 | | t |5/2/2014|3/5/2012|4/2/2010| 99 | 1 p1 | 4 | x |5/8/2014|3/4/2012|5/9/2015| 22 | 2 p2 | 3 | y |8/1/2015|5/6/2011|7/8/2010| 20 | 3
here want records multiple rows equal values.the condition ano,code,type,cps,tax needs directly compared. and, if ex_date , rd_date equal or 10days of each other considered duplicate.note: wanted ignore date1 column.
so, above schema should come like:
ano | code |type | date1 | ex_date|rd_date |cps | tax ______|_______| _____|______ |_ ______|_______ |____|__________ b1 | | t |4/1/2014|3/2/2012|4/2/2010| 99 | 1 b1 | | t |5/2/2014|3/5/2012|4/2/2010| 99 | 1
its great, if 1 can please me plsql.sql server ok.
oracle 11g r2 schema setup:
create table test ( ano, code,"type", date1, ex_date,rd_date,cps, tax ) select 'b1', 'am', 't', to_date( '2014-04-01', 'yyyy-mm-dd' ), to_date( '2012-03-02', 'yyyy-mm-dd' ), to_date( '2010-04-02', 'yyyy-mm-dd' ), 99, 1 dual union select 'b1', 'am', 't', to_date( '2014-05-02', 'yyyy-mm-dd' ), to_date( '2012-03-05', 'yyyy-mm-dd' ), to_date( '2010-04-02', 'yyyy-mm-dd' ), 99, 1 dual union select 'p1', '4', 'x', to_date( '2014-05-08', 'yyyy-mm-dd' ), to_date( '2012-03-04', 'yyyy-mm-dd' ), to_date( '2015-05-09', 'yyyy-mm-dd' ), 22, 2 dual union select 'p2', '3', 'y', to_date( '2015-08-01', 'yyyy-mm-dd' ), to_date( '2011-05-06', 'yyyy-mm-dd' ), to_date( '2010-07-08', 'yyyy-mm-dd' ), 20, 3 dual;
query 1:
select * test t exists ( select 'x' test x x.rowid <> t.rowid , x.ano = t.ano , x.code = t.code , x."type" = t."type" , x.cps = t.cps , x.tax = t.tax , x.ex_date between t.ex_date - interval '10' day , t.ex_date + interval '10' day , x.rd_date between t.rd_date - interval '10' day , t.rd_date + interval '10' day )
| ano | code | type | date1 | ex_date | rd_date | cps | tax | |-----|------|------|-------------------------|-------------------------|-------------------------|-----|-----| | b1 | | t | may, 02 2014 00:00:00 | march, 05 2012 00:00:00 | april, 02 2010 00:00:00 | 99 | 1 | | b1 | | t | april, 01 2014 00:00:00 | march, 02 2012 00:00:00 | april, 02 2010 00:00:00 | 99 | 1 |
Comments
Post a Comment