1

1 つの列の値を 1 つのセルにグループ化する SQL 選択ステートメントを作成する必要があります。

例えば

table name: Customer_Hobbies
+------------+------------+-----------+
| CustomerId |     Age    |  Hobby    |
+------------+------------+-----------+
| 123        |     17     |  Golf     |
| 123        |     17     |  Football |
| 324        |     14     |  Rugby    |
| 627        |     28     |  Football |
+------------+------------+-----------+

返すべき…

+------------+------------+----------------+
| CustomerId |     Age    |  Hobbies       |
+------------+------------+----------------+
| 123        |     17     |  Golf,Football |
| 324        |     14     |  Rugby         |
| 627        |     28     |  Football      |
+------------+------------+----------------+

これは可能ですか?

注意: データが特に賢明な方法でレイアウトされていないことはわかっていますが、それを変更することはできません。

4

1 に答える 1

1

あなたが欲しいgroup_concat()

select customerId, age, group_concat(hobby) as hobbies
from t
group by customerId, age
于 2013-03-22T13:12:38.260 に答える