I have the following problem: I need to sort some products where one needs to be a specific row and others to be random.
So if I have products: A B C D, I need for example B to be the third product while others can be random like:
C 1
A 2
B 3
D 4
Best shot I have tried is (3 is a dynamic value):
SELECT
product_name,
CASE
WHEN product = 'B' THEN 3
ELSE ( CASE WHEN rownum < 3 THEN rownum ELSE rownum + 1 END )
END sorting
FROM
products
ORDER BY
sorting ASC;
but I'm not always getting the desired outcome.
Any help or lead is appreciated.
rownumdefined or generated?CASE WHEN: you can makerownum < 3the second case in the topCASE WHENexpression.