0

私はテーブルを持っています、そしてそれはこのように見えます、

mysql> select * from match_info;
+---------------+---------+------------+-------------+-----------+
| match_info_id | user_id | body_types | hair_colors | ethnicity |
+---------------+---------+------------+-------------+-----------+
|             1 |       1 | 1,5,9,13   | 1,5,9,13    | 2,6,10    |
|             2 |       2 | 1,5,9,13   | 5           | 1,5,9     |
+---------------+---------+------------+-------------+-----------+

body_typeshair_colorsおよび各テーブルの列を使用ethnicityしてルックアップ テーブルを使用しました。idname

上記を使用して、特定のユーザーのすべての値を選択する必要があります。このような。

body_type テーブルから。

ボディタイプ:Skinny, Muscular, Large, Ripped

髪色:Blonde, Dark Brown, Strawberry Blonde, Dark Blondeetc....

上記の結果を得るために選択クエリを作成する方法を誰か教えてください。

誰かが私を助けてくれることを願っています。

ありがとうございました。

4

1 に答える 1

0

テーブルを結合して、find_in_seton 句に関数を配置できます。これを試して :

select t.match_info_id, t.user_id,
    group_concat(distinct a.name) as body_types,
    group_concat(distinct b.name) as hair_colors,
    group_concat(distinct c.name) as ethnicity
from match_info as t
    inner join body_type as a on find_in_set(a.id,t.body_types)
    inner join hair_color as b on find_in_set(b.id,t.hair_colors)
    inner join ethnicity as c on find_in_set(c.id,t.ethnicity)
group by t.match_info_id, t.user_id

必要に応じてleft join代わりに使用することもできます。inner join

于 2015-06-07T03:21:07.640 に答える