1

I have done this before but I forgot where in my app I have this code.

I have the following data for ex:

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

Now I want to return something from this table using mysql like:

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

The idea here is to group Extras and Price field and get the Room Type.

4

1 回答 1

2

Use GROUP_CONCAT:

SELECT
    GROUP_CONCAT(`Room Type` SEPARATOR ' & ') Type AS `Room Type`,
    Extras,
    Price
FROM yourtable
GROUP BY Extras, Price
于 2012-04-07T03:00:15.917 回答