我有这个查询:
SELECT * FROM table WHERE key LIKE '1,2,3,%' OR key LIKE '1,2,%' OR key LIKE '1,%'
是否可以根据首先匹配的条件对从该查询返回的记录进行排序。我想先获取所有匹配的记录key LIKE '1,2,3,%',然后再key LIKE '1,2,%'获取其他匹配的记录。
key LIKE '1,2,3,%'
key LIKE '1,2,%'
例如,如果我有以下记录:
key: "1,2,3,4" key: "1,2,5" key: "1,4" key: "1,2,5,6" key: "1,3" key: "1,2,3,4,7" key: "1,2,4"
我希望对它们进行如下排序:
key: "1,2,3,4" key: "1,2,3,4,7" key: "1,2,4" key: "1,2,5" key: "1,2,5,6" key: "1,3" key: "1,4"
有可能吗?
.... ORDER BY CASE WHEN key LIKE '1,2,3,%' THEN 1 WHEN key LIKE '1,2,%' THEN 2 ELSE 3 END