sql - Compare a group of rows in oracle -


i have table having coloumns,

id    |       branch    |       start_num      |    end_num   123             s                    25                95 234             s                    45                105 445             s                    46                90 556             m                    56                129 78              m                    76                199 87              m                    80                110 987             m                    89                128 777             m                    100               1500 

i want first group result on basis of branch(m,s here).then want records lies insubset of master start , end no being first row of group.here compare s group 25-95 , in m group 56-129. hence answer (i writing rows first element)

123 445 556 87 

you can use below given query in mssql.

select b.id branch b inner join (         select distinct m.branch,c.start_num,c.end_num         branch m         outer apply(             select top 1 start_num,end_num             branch             branch = m.branch             order start_num         ) c ) l on b.branch = l.branch , b.start_num >= l.start_num , b.end_num <= l.end_num 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -