SQL / SQLite Order By Tiered Based Values
I have tried googling for how to do this but I don't know what to search for. I want to select data from a database (sqlite) but I want to be able to give records higher priority than others based on a couple of conditions. I have a table that holds my data, and when I select from the table I want to have the ability to ORDER BY a teamName field, and a percentSuccess field. Normally, if I just do this: SELECT * FROM table ORDER BY teamName, percentSuccess DESC I will get everything ordered first by teamName (in ASC alphabetical order) and the by perscentSuccess (in DESC order - so highest success rate first). So to achieve prioritizing by teamName, I have to use a CASE in the ORDER BY: SELECT * FROM table ORDER BY CASE teamName WHEN 'charlie' THEN 0 WHEN 'alpha' THEN 1 WHEN 'beta' THEN 2 END (this will order the results so that any records with teamName 'charlie' come first, before alpha and beta) Now... it's clear that I am partial to team Charlie. But.... if team Alpha or Beta, have some players that have a high enough success rate compared to some slackers on team Charlie... I want to give those players on Alpha and Beta better priority than the slackers on Charlie. For example: If a player is on team Charlie, and they have a success rate >= 0.75 (75%) then they should have top priority. If a player from Alpha or Beta has a success rate >= 0.75, they should outrank a player from Charlie that has a success rate <= 0.74 and >= 0.50. But if a player from Alpha or Beta has success <= 0.74 and >= 0.50 they rank below players from Charlie within the same success tier. How can I do this, or what is this style of ordering called so I can search for it?