Let the table - TableA is as follows,
| Row_No | COL1 | COL2 | COL3 | COL4 |
| ------------ | ------------ | ------------ | ------------ | ------------ |
| 1 | 1234 | SER1 | Y | ABC |
| 2 | 1234 | SER2 | N | DEF |
| 3 | 3456 | SER1 | Y | XYZ |
| 4 | 3456 | SER2 | Y | PQR |
| 5 | 5678 | SER1 | N | QAZ |
| 6 | 5678 | SER2 | N | SRT |
Is it possible to get the result as shown below using oracle sql ?
| Row_No | COL1 | COL2 | COL3 | COL4 |
| ------------ | ------------ | ------------ | ------------ | ------------ |
| 1 | 1234 | SER1 | Y | ABC |
| 3 | 3456 | SER1 | Y | XYZ |
| 5 | 5678 | SER1 | N | QAZ |
The unique row selection rules are:
- Among rows with same value in COL1,
- Select the row with Y for COL3. (For example, among rows: 1,2; 1st one has Y for COL3)
- If both rows have same value(Y/N) for COL3 then select one of the row (among 3, 4 -> 3 & 5,6 -> 5 ).
1条答案
按热度按时间wqnecbli1#
If you sort rows using
row_number
analytic function and put named conditions into itsorder by
clause, you'd get this:Sample data:
Query begins here: