Oracle SQL Conditional Select Query -


this question has answer here:

i have table below

uid    rid   time_type    date_time  a11    1     2            5/4/2013 00:32:00 (row1) a43    1     1            5/4/2013 00:32:01 (row2) a68    1     1            5/4/2013 00:32:02 (row3) a98    1     2            5/4/2013 00:32:03 (row4) a45    1     2            5/4/2013 00:32:04 (row5) a94    1     1            5/4/2013 00:32:05 (row6) a35    1     2            5/4/2013 00:32:07 (row7) a33    1     2            5/4/2013 00:32:08 (row8) 

can use normal select query extract data such becomes

uid    rid   time_type    date_time  a43    1     1            5/4/2013 00:32:01 (row2) a98    1     2            5/4/2013 00:32:03 (row4) a94    1     1            5/4/2013 00:32:05 (row6) a35    1     2            5/4/2013 00:32:07 (row7) 

the date_time field in asc order. logic time_type '1' needs paired next time_type '2' of same rid. if time_type '1' or '2' appears in group of 2 or more ordered date_time, take earlier 1 , ignore rest.

can done?

try query:

with src (   select tst.*,            case when time_type <> lag( time_type) on ( partition rid order date_time, time_type )              1 else 0          end take_me   tst )  select * src take_me = 1 order rid, date_time; 

here sql fiddle demo


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -