sql - Limiting output with different criterias -
i have following sql statement:
select row_number() over(), car, group, yearout (select..... )inner year(inner.yearout) between '2010' , '2030' order inner.group)temp
the output
1 test1 1 2010 2 test2 1 2010 3 test3 1 2012 4 test1 2 2010 5 test1 3 2011
and on.
there table called outerno filled like:
no yearo amnt 1 2010 10 2 2010 15 3 2010 5 4 2010 10 5 2010 15 6 2010 8 1 2011 4 2 2011 15
and on.
there 6 groups in table each year.
now problem need limit output of query stated in outerno table. need first 10 row 2010 group 1, first 15 rows of 2010 group 2 , on. each year , group there value in outerno.
i tried use row_number don't know how limit output in way since needing example rows 1-10, 50-65, 83-88 , on.
any idea on how this?
thanks in advance help.
thevagabond
you'd use row_number() give record numbers per group. add clause row numbers desired number. in row_number's order can spcify records prefer.
select row_number() on (), car, group, yearout ( select row_number() on (partition inner.group, inner.yearout order inner.car) rn, inner.car, inner.group, inner.yearout (select..... ) inner inner.yearout between '2010' , '2030' order inner.group ) all_records all_records.rn <= ( select amnt outerno outerno.year = all_records.yearout , outerno.no = all_records.group );
btw: wouldn't choose group
column name, reserved word in sql.
Comments
Post a Comment