I need a way to sort based on date, with all rows of a certain type to be grouped last (but also sorted by date).
For instance, suppose I have a DB column where values can take on ["A", "B", "C"]. In the same table, there is also a dateCreated column.
I want all rows with "A" to be last and all rows (including those within group A) to be sorted by date created (ascending for simplicity sake)
For instance, if I had the rows:
ID | enum | dateCreated |
---|---|---|
1 | A | 2020-01-01 |
2 | A | 2020-01-03 |
3 | A | 2020-01-02 |
4 | B | 2020-02-03 |
5 | B | 2020-02-01 |
6 | C | 2020-02-02 |
The resulting order should be:
5,6,4,1,3,2
To explain, all of the non-A rows come first, ordered by date. Then all of the A rows, also ordered by date.
I see the SO post QueryDsl orderBy specific string values which almost provides what I need, but it is unfortunately not nuanced enough for my use case.