please help me out with a solution to this problem..
table is like this -
Type | SubType | Flag | Value
--------------------------------
123 | A1 | Y | 101
--------------------------------
123 | A2 | Y | 102
------------------------------
123 | A3 | Y | 103
------------------------------
124 | A4 | N | 104
------------------------------
124 | A5 | N | 105
------------------------------
124 | A6 | N | 106
------------------------------
125 | A7 | Y | 107
------------------------------
125 | A8 | Y | 108
------------------------------
125 | A9 | N | 109
------------------------------
125 | A10 | N | 110
requirement is to select rows based on certain conditions - if all flags are Y for a particular type then select only row with lowest subtype, if all flags are N for a particular type then select all rows of that type , if flags for a type are combination of Y and N then select 2 rows for that type - one with lowest subtype of flag Y and one with lowest subtype of flag N.
So the output of above table should look like -
Type | SubType | Flag | Value
------------------------------
123 | A1 | Y | 101
------------------------------
124 | A4 | N | 104
------------------------------
124 | A5 | N | 105
------------------------------
124 | A6 | N | 106
------------------------------
125 | A7 | Y | 107
------------------------------
125 | A9 | N | 109
Sorry for bad table formats , Thanks in advance for looking into this.