I have a complex prioritisation algorithm that I want to write in SQL to when return prioritised pages of data.
Some of these are prioritised according to fixed values, other are ordered by variable values. i.e.
// Initial sort on ATTR1 (value1/value2 is higher than value3)
if ATTR1 = value1 or value2
then orderBy creationDate, then modifiedDate, then author
else if ATTR1 = value3
then
// if ATTR1 = value3, do secondary sort on ATTR2 (value4 is higher than value5)
if ATTR2 = value4
then orderBy oldPriority, then modifiedDate, then creationDate, then author
if ATTR2 = value5
then orderBy creationDate, then modifiedDate
I have had a look at SQL CASE WHEN, but not sure how to make that work with the second level of attribute comparison.
Is CASE WHEN a suitable tool for achieving this? Does anyone have any tips on dealing with the additional levels of complexity?
Thank you in advance!