SQL: Is it possible to 'group by' according to 'like' function's results?

前端 未结 5 1446
暖寄归人
暖寄归人 2021-02-20 13:44

I am using Oracle SQL and I want to group some different rows that \'like\' function results. To elaborate with an example:


Let\'s assume I have a table MESA w

5条回答
  •  星月不相逢
    2021-02-20 14:32

    Sure:

    WITH Fruits AS (
        SELECT 
            CASE 
               WHEN m.str LIKE '%APPLE%' THEN 'Apple'
               WHEN m.str LIKE '%ORANGE%' THEN 'Orange' 
            END AS FruitType           
        FROM MESA m
        WHERE m.str LIKE '%FRUIT%')
    SELECT FruitType, COUNT(*) 
    FROM Fruits
    WHERE FruitType IN ('Apple', 'Orange')
    GROUP BY FruitType;
    

提交回复
热议问题