Question : split rows in a table into groups based on a criteria

hi Gurus,

i have a table as below. i need to split the data in the table into 5 groups equally for all rows with status='F'  and not assigning more than 200 rows per group even though i can have more than 1000 rows with status ='F' as i need to only fetch 1000 at a time. also the groups should be created only if the total no of rows with status="F" exceed 40 only and at any given time and they should not fetch more than 1000 rows. also if the table has only say 100 rows with status F then i need to have 5 groups with 20 rows each.
  thanks in advance for your help.
since this is urgent i am assigning 500 points to it.

table A:

filename varchar (35)
status varchar (15)

thanks

Answer : split rows in a table into groups based on a criteria

i had already given the query which takes care of > 40 and status ='F' and records < 1001

Below is the ntile query for the same which can take care of all the three above.

select filename, status,ntile(5) over(order by filename) mygroup
from (
select  from mytable where status='F'
and (select count(*) from mytable where status='F') >40 and rownum < 1001
)
order by mygroup;

I think we do not need the below query as you can easily do it with NTILE function... I am just giving the modified version here as well..

select filename, status, mod(rr,5)+1 mygroup from
(
select filename, status , rownum rr from mytable
where status ='F'
and (select count(*) from mytable where status='F') >40
)
where rr < 1001
orer by mygroup;

Thanks,
Random Solutions  
 
programming4us programming4us