So, I want to create a formula for ordering things by popularity, but I don’t want to create a stored procedure or function. I’d like the function just to be in my query.
So, is there a way to do something like
SELECT cols
FROM tables
WHERE conditions
ORDER BY function(){ logic using cols } DESC LIMIT 10
or something like that?
You want to call a function but you don’t want to define a function? Okay…
You can use expressions in the ORDER BY clause, including
CASEwhich is pretty powerful:But it’s often easier to do the calculation in your select-list and then order by that calculated column: