Extending question which is there on Write sql query to wrap row data
DEPARTMENT | SUB_DEPT | EMPLOYEE | SALARY
DEPT1 | SUB_DEPT1 | ABC | 20000
DEPT1 | SUB_DEPT1 | DEF | 30000
DEPT1 | SUB_DEPT2 | GHI | 25000
DEPT1 | SUB_DEPT2 | JKL | 42000
DEPT2 | SUB_DEPT3 | MNO | 42500
DEPT2 | SUB_DEPT3 | PQR | 35000
DEPT3 | SUB_DEPT4 | STU | 36000
DEPT3 | SUB_DEPT5 | VWX | 36040
retrieve like
DEPARTMENT | SUB_DEPT | EMPLOYEE | SALARY
DEPT1 | SUB_DEPT1 | ABC | 20000
| | DEF | 30000
| SUB_DEPT2 | GHI | 25000
| | JKL | 42000
DEPT2 | SUB_DEPT3 | MNO | 42500
| | PQR | 35000
DEPT3 | SUB_DEPT4 | STU | 36000
| SUB_DEPT5 | VWX | 36040
It means
1) Wrapping must apply for two columns.
2) Wrapping text must be for first row i.e. DEPT1 must present at first row only, DEPT2 present for 5th row.
Please help me out for this.
Thanks in advance.
You can follow the same process as your original post. Create a
row_number()for each unique department, then do the same thing for each unique department and sub_dept partition:See SQL Fiddle with Demo
Result: