質問編集履歴
7
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -102,6 +102,6 @@
|
|
102
102
|
|
103
103
|
|1 |aaa |ホワイト|
|
104
104
|
|
105
|
-
このような結果になったのですが、clを,区切りに
|
105
|
+
このような結果になったのですが、clを,区切りにして1レコードに格納したいです。
|
106
106
|
|
107
107
|
よろしくお願いします。
|
6
sql修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -72,22 +72,36 @@
|
|
72
72
|
|
73
73
|
表示する際のSQL
|
74
74
|
|
75
|
+
|
76
|
+
|
75
77
|
```sql
|
76
78
|
|
77
|
-
select
|
79
|
+
select user_id,name,colorname
|
78
|
-
|
79
|
-
,STRING_AGG(c.colorname,',') as color_name_list
|
80
80
|
|
81
81
|
from(
|
82
82
|
|
83
|
-
select *, value as c
|
83
|
+
select *, value as cl
|
84
84
|
|
85
|
-
from sample outer apply string_split(s
|
85
|
+
from sample as s outer apply string_split(s.color,',')
|
86
86
|
|
87
|
-
) a
|
87
|
+
) as a
|
88
88
|
|
89
|
-
on c
|
89
|
+
inner join master_color as c
|
90
90
|
|
91
|
-
|
91
|
+
on c.color_cd = a.cl
|
92
|
+
|
93
|
+
|
92
94
|
|
93
95
|
```
|
96
|
+
|
97
|
+
これで
|
98
|
+
|
99
|
+
|user_id|name |cl |
|
100
|
+
|
101
|
+
|1 |aaa |ブラック|
|
102
|
+
|
103
|
+
|1 |aaa |ホワイト|
|
104
|
+
|
105
|
+
このような結果になったのですが、clを,区切りに戻したいのですがどうしたらいいのでしょうか?
|
106
|
+
|
107
|
+
よろしくお願いします。
|
5
sql修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -74,12 +74,20 @@
|
|
74
74
|
|
75
75
|
```sql
|
76
76
|
|
77
|
-
select a.user_id,a.name
|
77
|
+
select a.user_id,a.name
|
78
78
|
|
79
|
-
|
79
|
+
,STRING_AGG(c.colorname,',') as color_name_list
|
80
80
|
|
81
|
-
|
81
|
+
from(
|
82
82
|
|
83
|
+
select *, value as color
|
84
|
+
|
85
|
+
from sample outer apply string_split(sample.color,',')
|
86
|
+
|
87
|
+
) a inner join master_color as c
|
88
|
+
|
83
|
-
on c.color = a.color
|
89
|
+
on c.color_cd = a.color
|
90
|
+
|
91
|
+
group by a.user_id,a.name
|
84
92
|
|
85
93
|
```
|
4
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -68,6 +68,10 @@
|
|
68
68
|
|
69
69
|
|
70
70
|
|
71
|
+
|
72
|
+
|
73
|
+
表示する際のSQL
|
74
|
+
|
71
75
|
```sql
|
72
76
|
|
73
77
|
select a.user_id,a.name,c.colorname
|
3
ソース追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -52,6 +52,22 @@
|
|
52
52
|
|
53
53
|
```
|
54
54
|
|
55
|
+
Controller
|
56
|
+
|
57
|
+
```php
|
58
|
+
|
59
|
+
$colors = Request::Input('color');
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
//配列を文字列に変換してテーブルに登録しています。
|
64
|
+
|
65
|
+
$color = implode(",",$colors);
|
66
|
+
|
67
|
+
```
|
68
|
+
|
69
|
+
|
70
|
+
|
55
71
|
```sql
|
56
72
|
|
57
73
|
select a.user_id,a.name,c.colorname
|
2
追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,9 +28,11 @@
|
|
28
28
|
|
29
29
|
表示する際に
|
30
30
|
|
31
|
-
|
|
31
|
+
|user_id|name|color |
|
32
32
|
|
33
|
-
|ブラック,ホワイト|
|
33
|
+
|01 |a |ブラック,ホワイト|
|
34
|
+
|
35
|
+
|
34
36
|
|
35
37
|
と表示させたいです。
|
36
38
|
|
1
ソース追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -49,3 +49,15 @@
|
|
49
49
|
|
50
50
|
|
51
51
|
```
|
52
|
+
|
53
|
+
```sql
|
54
|
+
|
55
|
+
select a.user_id,a.name,c.colorname
|
56
|
+
|
57
|
+
from sample1 as a
|
58
|
+
|
59
|
+
inner join color as c
|
60
|
+
|
61
|
+
on c.color = a.color
|
62
|
+
|
63
|
+
```
|