2012-04-07 59 views
1

我已经完成了此操作,但是我忘记了应用程序中的哪个位置。如何将GROUP BY的一个或多个值与GROUP BY结合

我有恩以下数据:

Room Type   Extras   Price 
Deluxe   Extra Person  150 
Super Deluxe  Extra Person  150 
Deluxe   Breakfast  250 
Super Deluxe  Breakfast  250 
Junior Suite  Extra Person  200 

现在我想用回从这个表中的东西的MySQL这样的:

Room Type      Extras   Price 
Deluxe & Super Deluxe   Extra Person  150 
Deluxe & Super Deluxe   Breakfast  250 
Junior Suite     Extra Person  200 

这里的想法是要额外组和价格领域,获得房间类型。

回答

2

使用GROUP_CONCAT

SELECT 
    GROUP_CONCAT(`Room Type` SEPARATOR ' & ') Type AS `Room Type`, 
    Extras, 
    Price 
FROM yourtable 
GROUP BY Extras, Price 
+0

感谢ü非常多。就是这个。 – jaypabs 2012-04-07 03:15:03