質問編集履歴
3
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -61,7 +61,7 @@
|
|
61
61
|
|
62
62
|
**2022/2/3 19:27 追記**
|
63
63
|
実現したい取得結果は下記の通りです。
|
64
|
-
|food_code|food_name|
|
64
|
+
|food_code|food_name|produnction_code|
|
65
65
|
|:--|:--:|--:|
|
66
66
|
|001,002|りんご,バナナ|AAA,BBB|
|
67
67
|
|
2
修正依頼を受け追記。
title
CHANGED
File without changes
|
body
CHANGED
@@ -59,4 +59,23 @@
|
|
59
59
|
from food
|
60
60
|
```
|
61
61
|
|
62
|
+
**2022/2/3 19:27 追記**
|
63
|
+
実現したい取得結果は下記の通りです。
|
64
|
+
|food_code|food_name|food_name|
|
65
|
+
|:--|:--:|--:|
|
66
|
+
|001,002|りんご,バナナ|AAA,BBB|
|
62
67
|
|
68
|
+
下記SQLにて実現は出来ましたが、よりすっきりとしたコードに出来ないか模索中です。
|
69
|
+
```ここに言語を入力
|
70
|
+
select
|
71
|
+
array_to_string(array_agg(distinct food_code), ','),
|
72
|
+
array_to_string(array_agg(distinct food_name), ','),
|
73
|
+
array_to_string(array_agg(distinct produnction_code), ',')
|
74
|
+
-- into out_food_code,out_food_name, out_produnction_code
|
75
|
+
from food
|
76
|
+
```
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
1
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -39,22 +39,24 @@
|
|
39
39
|
,'会社AAA'
|
40
40
|
);
|
41
41
|
-- 試したselect文
|
42
|
+
select
|
42
|
-
|
43
|
+
array_to_string(food_code,','),
|
44
|
+
array_to_string(food_name,','),
|
45
|
+
array_to_string(produnction_code,',')
|
43
46
|
-- into out_food_code,out_food_name, out_produnction_code
|
44
47
|
from food;
|
45
48
|
```
|
46
|
-
selectすると下記結果となりますが、
|
47
|
-
| food_code | food_name | produnction_code |
|
48
|
-
|:--|:--:|--:|
|
49
|
-
|001| りんご | AAA |
|
50
|
-
|001| りんご | BBB |
|
51
|
-
|002| バナナ | AAA |
|
52
49
|
|
53
|
-
|
50
|
+
**2022/2/2 23:09 追記**
|
54
|
-
|
51
|
+
下記select文で行えるかもしれませんが、手元に実行環境がないため、3日に試します。
|
55
|
-
|:--|:--:|--:|
|
56
|
-
|001| りんご | AAA |
|
57
|
-
|002| バナナ | BBB |
|
58
52
|
|
59
|
-
|
53
|
+
```ここに言語を入力
|
54
|
+
select
|
55
|
+
array_to_string(array_agg(distinct food_code), ','),
|
56
|
+
array_to_string(array_agg(distinct food_name), ','),
|
57
|
+
array_to_string(array_agg(distinct produnction_code), ',')
|
58
|
+
-- into out_food_code,out_food_name, out_produnction_code
|
59
|
+
from food
|
60
|
+
```
|
60
61
|
|
62
|
+
|