sql - Oracle query - without temporary table -


i'm new oracle , need query. have table data samples /records like:

name | datetime -----------    | 20140414 10:00    | 20140414 10:30    | 20140414 11:00 b    | 20140414 11:30 b    | 20140414 12:00    | 20140414 12:30    | 20140414 13:00    | 20140414 13:30 

and need "group"/get informations form:

name | datetime_from  | datetime_to ----------------------------------    | 20140414 10:00 | 20140414 11:00 b    | 20140414 11:30 | 20140414 12:00    | 20140414 12:30 | 20140414 13:30 

i couldnt find solution query similar this. please me?

note: dont want use temporary tables.

thanks, pavel

you need find periods values same. easiest way in oracle use lag() function, logic, , aggregation:

select name, min(datetime), max(datetime) (select t.*,              sum(case when name <> prevname 1 else 0 end) on (order datetime) cnt       (select t.*, lag(name) on (order datetime) prevname             table t            ) t      ) t group name, cnt; 

what count, given value of datetime, number of times name has switched on or before datetime. identifies periods of "constancy", used aggregation.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -