Way to try multiple SELECTs till a result is available?

前端 未结 4 751
梦毁少年i
梦毁少年i 2020-11-27 23:36

What if I want to search for a single row in a table with a decrementing precision, e.g. like this:

SELECT * FROM image WHERE name LIKE \'text\' AND group_id         


        
4条回答
  •  不知归路
    2020-11-28 00:11

    SELECT *, 
    CASE WHEN name like 'text' AND group_id = 10 THEN 1
    WHEN name like 'text' THEN 2
    WHEN group_id = 10 THEN 3
    ELSE 4
    END ImageRank
    FROM image
    WHERE ImageRank <> 4
    ORDER BY ImageRank ASC
    LIMIT 1
    

    This would be a pseudo-solution approach but I'm not entirely sure if the syntax in your scenario would allow for it

提交回复
热议问题