If I've a table like below,
tid pid bid fl fq fo
---------------------------
7114 3823 2341 3 1 1
7114 3823 2340 0 0 0
7114 3823 2350 0 0 0
7114 3850 4515 0 0 0
7114 3474 2350 0 0 0
7114 3474 2340 1 2 1
from this table I need to get the rows of columns pid,bid,fl and fq where its fo=1 by grouping pid
and the expected output will be:
pid bid fl fq fo
----------------------
3823 2341 3 1 1
3823 2340 3 1 1
3823 2350 3 1 1
3474 2350 1 2 1
3474 2340 1 2 1
NOTE :for example (consider the table) 1st and 2nd row have the same pid ie.3823 and among those two rows one row has fo=1(ie. 1st row) so i need to get the pid of 1st row and the fl,fq and bid of the second row,so the output should be
pid bid fl fq fo
----------------------
3823 2341 3 1 1
3823 2340 3 1 1
3823 2350 3 1 1
sample data:
create table com (tid int,pid int,bid int,fl int,fq int,fo int);
insert into com values (7114 , 3823, 2341, 3 , 1 , 1),
(7114 , 3823 , 2340 , 0 ,0 , 0),(7114 , 3823 , 2350 , 0 , 0 , 0),
(7114 ,3850, 4515, 0 , 0 , 0),(7114 , 3474 , 2350, 0 , 0, 0),
(7114 ,3474, 2340 , 1 , 2 , 1);
florfq?pidpidie.3823and among those two rows one row hasfo=1so i need to get thepidof 1st row and thefl,fqandbidof the second row