I am trying to sort by whether '/us/' is in a url. I currently have:
SELECT is_live, store_url from my_table where item_id = 1306085
ORDER BY (CASE WHEN store_url LIKE '%/us%' THEN 1 ELSE 0 END) DESC
Is there a cleaner way to do this, or is the above the only way? Conceptually, I'm looking for something a bit more readable, such as:
ORDER BY store_url.contains('/us/') DESC
ORDER BY store_url LIKE '%/us%' DESCshould be fine... if you want it to look more like a function call you can use the INSTR function... though that returns the actual found position, so you would want the ordering onINSTR(...)=0 ASCto prevent unwanted ranking by location in string.