Here is my table data from which i want to find a specific id by comparing multiple rows..
onetsoc_code element_id data_value
11-1011.00 1.B.1.a 1.33
11-1011.00 1.B.1.b 2.00
11-1011.00 1.B.1.c 2.67
11-1011.00 1.B.1.d 3.67
11-1011.00 1.B.1.e 7.00
11-1011.00 1.B.1.f 5.33
11-1011.00 1.B.1.g 5.00
11-1011.00 1.B.1.h 6.00
11-1011.00 1.B.1.i 0.00
11-1021.00 1.B.1.a 1.33
11-1021.00 1.B.1.b 1.33
11-1021.00 1.B.1.c 1.00
11-1021.00 1.B.1.d 3.33
11-1021.00 1.B.1.e 7.00
11-1021.00 1.B.1.f 3.67
11-1021.00 1.B.1.g 5.00
11-1021.00 1.B.1.h 6.00
11-1021.00 1.B.1.i 4.00
11-1031.00 1.B.1.a 1.00
11-1031.00 1.B.1.b 3.67
11-1031.00 1.B.1.c 3.67
11-1031.00 1.B.1.d 4.67
11-1031.00 1.B.1.e 7.00
This is my table so i want those onetsoc_code where the
1.B.1.g 5.00
1.B.1.h 6.00
1.B.1.i 4.00
If you look at the table then you will find 11-1021.00 is the result which i want.
So this is the logic what i want you for got 1.B.1.a to 1.B.1.f. I only want to compare three rows at a moment and want the single onetsoc_code associated with those data.
The rows with 1.B.1.g, 1.B.1.h, 1.B.1.i is available for all onetsoc_code so i just need those onetsoc_code which has above given condition like again,
1.B.1.g 5.00
1.B.1.h 6.00
1.B.1.i 4.00
You can group by
onetsoc_codeand filter for those groups that contain threeDISTINCTrecords:See it on sqlfiddle.
Of course, if uniqueness is guaranteed one can save the expense of the
DISTINCToperation and just use plain oldCOUNT(*)instead.