I have a DB column named ask_code
and ask_grouping
which says if the ask_code
is grouping or not (like a boolean for G = yes). How I do a SELECT query to get all the ask_code
by grouping?
Something like that:
| ask_code | ask_grouping | reference_id |
| A1 | | 1 |
| TOTAL | G | 1 |
| AREA | G | 1 |
|POPULATION| G | 1 |
| A2 | | 2 |
| TOTAL | G | 2 |
| AREA | G | 2 |
And I want:
| ask_code | grouping |
| A1 | TOTAL |
| A1 | AREA |
| A1 | POPULATION |
| A2 | TOTAL |
| A2 | AREA |
2
Answers
There is no ordering defined, so the output is not in the desired order:
output:
I just left
reference_id
in the output, but that can be left out. Still the ordering is unknown, so possibly incorrect.see: DBFIDDLE
You may try with max window function as the following:
see demo