回答編集履歴
1
追記
test
CHANGED
@@ -11,3 +11,37 @@
|
|
11
11
|
|
12
12
|
|
13
13
|
みたいにやって、group_cocantで他のテーブルから色名をとってきて結合します
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
# sample
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
```SQL
|
22
|
+
|
23
|
+
create table color(c_id int primary key,c_name varchar(30));
|
24
|
+
|
25
|
+
insert into color values(1,'ブラック'),(2,'ホワイト'),(3,'グレー');
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
create table user_color(u_id int ,c_id int,unique(u_id,c_id));
|
30
|
+
|
31
|
+
insert into user_color values(100,1),(100,2);
|
32
|
+
|
33
|
+
```
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
```SQL
|
38
|
+
|
39
|
+
select u_id,group_concat(c_name order by t1.c_id) as color
|
40
|
+
|
41
|
+
from color as t1
|
42
|
+
|
43
|
+
inner join user_color as t2 on t1.c_id=t2.c_id
|
44
|
+
|
45
|
+
group by u_id
|
46
|
+
|
47
|
+
```
|