0

我有以下查询:

SELECT 
        *
    FROM
        `Magic The Gathering`
    WHERE
        `set` =  'Magic 2013'
    ORDER BY
        FIELD (`rarity`, 'Mythic', 'Rare', 'Uncommon', 'Common', 'Land') ASC,
        FIELD (`type`, 'Planeswalker ', 'Creature', 'Instant', 'Sorcery', 'Enchantment', 'Artifact', 'Land') ASC
    LIMIT
        500

“类型”由多种关键字组成,例如“鹏洛客 - 阿耶尼”、“传奇神器”、“生物 - 精灵德鲁伊”等。

如何对类型进行排序,以便根据部分匹配的关键字(例如“鹏洛客”、“生物”、“即时”、“巫术”、“附魔”、“神器”、“土地”)显示?

4

2 回答 2

0

您可以通过使用 case 语句来做到这一点,例如:

Order by (case when type like '%Planeswalker%' then 1
            When ....
        end)
于 2013-08-17T21:11:33.010 回答
0

您可能可以 CASE WHEN用来解决您的问题。

SELECT 
        *
    FROM
        `Magic The Gathering`
    WHERE
        `set` =  'Magic 2013'
    ORDER BY
        FIELD (`rarity`, 'Mythic', 'Rare', 'Uncommon', 'Common', 'Land') ASC,
        CASE
            WHEN `type` LIKE '%Planeswalker%' THEN 1
            WHEN `type` LIKE '%Creature%' THEN 2
            WHEN `type` LIKE '%Instant%' THEN 3
            -- ...

        END CASE
    LIMIT
        500
于 2013-08-17T21:11:46.607 回答