mysql - SQL Query: How to filter for each set of value in the column? -
currently using sql fiddle insert below statment.
create table table1 ( rn int, pc varchar(25), pc1 varchar(25), grp varchar(25), e_id varchar(25) ); insert table1 (rn, pc, pc1, grp, e_id) values(111, 'a1', 'a1', '175', '100'); insert table1 (rn, pc, pc1, grp, e_id) values(111, 'a1', 'a1', '100', '90'); insert table1 (rn, pc, pc1, grp, e_id) values(112, 'b1', 'b1', '101', '90'); insert table1 (rn, pc, pc1, grp, e_id) values(112, 'b1', 'b1', '100', '90'); insert table1 (rn, pc, pc1, grp, e_id) values(112, 'b1', 'b1', '100', '90'); insert table1 (rn, pc, pc1, grp, e_id) values(113, 'c1', 'c1', '100', '90'); **as can see there 2 distinct rn numbers.** select * table1 rn in(select rn table1 group rn having count(*)>1) , (pc = pc1) , grp in (select max(grp) table1) , e_id in( select min(e_id) table1)
my current query able find correct row based on condition,
qn: how make conditions work each set of rn?.
thus result shld have 1 row 111 , 1 row 112.
i tried searching foreach not find solution.
**qn2: have added 1 row 1 rn only. out output previous qns should be
rn pc pc1 grp e_id 111 a1 a1 175 100 112 b1 b1 101 90 113 c1 c1 100 90 --> row 1 rn should output
perhaps want:
select rn, grp, e_id table1 rn in (select rn table1 group rn having count(*)>1) , (pc = pc1) group rn having grp = max(grp) , e_id = min(e_id)
Comments
Post a Comment