Mysql 使用字符串列选择特定输出

Mysql 使用字符串列选择特定输出,mysql,Mysql,我正在做一份关于一家酒店的报告,我需要总结一些关于他们预订的董事会的信息 现在,我的输出如下所示: SELECT meal.id, meal.title, SUM(CASE WHEN meal.id >= 600 THEN '1' ELSE '0' END) as NoofMeals FROM meal JOIN itinerary i ON i.id = meal.journeyid WHERE i.arrival BETWEEN '2015-01-01'

我正在做一份关于一家酒店的报告,我需要总结一些关于他们预订的董事会的信息

现在,我的输出如下所示:

SELECT meal.id, meal.title,
    SUM(CASE WHEN meal.id >= 600 THEN '1' ELSE '0' END) as NoofMeals
    FROM meal
    JOIN itinerary i ON i.id = meal.journeyid
    WHERE i.arrival BETWEEN '2015-01-01' AND '2015-01-01'
    GROUP BY meal.title
ID    | title                  | NoofMeals

608   | Dinner                 | 15
621   | Breakfast              | 478
648   | Lunch                  | 74
649   | Breakfast Box          | 5
655   | Lunch-Box              | 7
659   | American breakfast     | 73
671   | Continental breakfast  | 102
674   | All Inclusive          | 312
689   | All Inclusive from 3pm | 7
693   | Picnic                 | 47
我的输出如下所示:

SELECT meal.id, meal.title,
    SUM(CASE WHEN meal.id >= 600 THEN '1' ELSE '0' END) as NoofMeals
    FROM meal
    JOIN itinerary i ON i.id = meal.journeyid
    WHERE i.arrival BETWEEN '2015-01-01' AND '2015-01-01'
    GROUP BY meal.title
ID    | title                  | NoofMeals

608   | Dinner                 | 15
621   | Breakfast              | 478
648   | Lunch                  | 74
649   | Breakfast Box          | 5
655   | Lunch-Box              | 7
659   | American breakfast     | 73
671   | Continental breakfast  | 102
674   | All Inclusive          | 312
689   | All Inclusive from 3pm | 7
693   | Picnic                 | 47
我想要的输出是这样的,并将不同的值放在一起,比如所有的早餐(早餐、早餐盒、美式早餐和欧式早餐)或所有的全包(从下午3点开始全包和全包)。不幸的是,ID不是顺序的

title                  | NoofMeals

Dinner                 | 15
Breakfast              | 658
Lunch                  | 81
All Inclusive          | 319
Picnic                 | 7
我不再需要ID了,我只需要能够重命名餐名

我希望你能帮助我,请对我放松点,我对MySQL还很陌生

提前谢谢你

一个“快速而肮脏”的解决方案将利用字符串函数:

SELECT
  case
    when meal.title like '%Breakfast%' then 'Breakfast'
    when meal.title like '%All inclusive%' then 'All Inclusive'
    else meal.title
  end as title,
  ...
...
GROUP BY
  case
    when meal.title like '%Breakfast%' then 'Breakfast'
    when meal.title like '%All inclusive%' then 'All Inclusive'
    else meal.title
  end
适当的解决方案是添加一列,其中包含膳食类别:

id | title                  | category
---|------------------------|--------------
1  | Breakfast              | Breakfast
2  | American breakfast     | Breakfast
3  | Continental breakfast  | Breakfast
4  | All Inclusive          | All Inclusive
5  | All Inclusive from 3pm | All Inclusive
并通过
deal.category
而不是
deal.title

加入特定的膳食和分组。一个“快速而肮脏”的解决方案将使用字符串函数:

SELECT
  case
    when meal.title like '%Breakfast%' then 'Breakfast'
    when meal.title like '%All inclusive%' then 'All Inclusive'
    else meal.title
  end as title,
  ...
...
GROUP BY
  case
    when meal.title like '%Breakfast%' then 'Breakfast'
    when meal.title like '%All inclusive%' then 'All Inclusive'
    else meal.title
  end
适当的解决方案是添加一列,其中包含膳食类别:

id | title                  | category
---|------------------------|--------------
1  | Breakfast              | Breakfast
2  | American breakfast     | Breakfast
3  | Continental breakfast  | Breakfast
4  | All Inclusive          | All Inclusive
5  | All Inclusive from 3pm | All Inclusive

并通过
膳食加入特定的膳食和分组。类别
而不是
膳食。标题

请在所需输出中发布您的餐桌数据是野餐7或47?应该是47,抱歉!请在所需输出中发布您的表的数据是野餐7还是47?应该是47,对不起!非常感谢,它工作得很好!!我想我在那里坐得太久了,太想念森林了!谢谢:)万分感谢,它工作得很好!!我想我在那里坐得太久了,太想念森林了!谢谢:)