回答編集履歴
2
追記修正
test
CHANGED
@@ -50,21 +50,19 @@
|
|
50
50
|
|
51
51
|
```SQL
|
52
52
|
|
53
|
-
select
|
53
|
+
select `user_id`
|
54
54
|
|
55
|
-
,group_concat(if(
|
55
|
+
,group_concat(if(`key`='name',value,'') separator '') as `name`
|
56
56
|
|
57
|
-
,group_concat(if(
|
57
|
+
,group_concat(if(`key`='kana',value,'') separator '') as `kana`
|
58
58
|
|
59
|
-
,group_concat(if(
|
59
|
+
,group_concat(if(`key`='add',value,'') separator '') as `add`
|
60
60
|
|
61
|
-
,group_concat(if(
|
61
|
+
,group_concat(if(`key`='mail',value,'') separator '') as `mail`
|
62
62
|
|
63
|
-
,group_concat(if(
|
63
|
+
,group_concat(if(`key`='tel',value,'') separator '') as `tel`
|
64
64
|
|
65
|
-
from
|
65
|
+
from tbl_a
|
66
|
-
|
67
|
-
left join tbl_a as t1 on t0.user_id=t1.user_id
|
68
66
|
|
69
67
|
group by `user_id`;
|
70
68
|
|
1
追記
test
CHANGED
@@ -41,3 +41,31 @@
|
|
41
41
|
場合によってはピボットテーブル的な処理もできるかもしれませんが
|
42
42
|
|
43
43
|
上記で十分かと
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
# 追記
|
48
|
+
|
49
|
+
※ピボット処理を追記しておきます
|
50
|
+
|
51
|
+
```SQL
|
52
|
+
|
53
|
+
select t0.`user_id`
|
54
|
+
|
55
|
+
,group_concat(if(t1.key='name',t1.value,'') separator '') as `name`
|
56
|
+
|
57
|
+
,group_concat(if(t1.key='kana',t1.value,'') separator '') as `kana`
|
58
|
+
|
59
|
+
,group_concat(if(t1.key='add',t1.value,'') separator '') as `add`
|
60
|
+
|
61
|
+
,group_concat(if(t1.key='mail',t1.value,'') separator '') as `mail`
|
62
|
+
|
63
|
+
,group_concat(if(t1.key='tel',t1.value,'') separator '') as `tel`
|
64
|
+
|
65
|
+
from (select distinct user_id from tbl_a) as t0
|
66
|
+
|
67
|
+
left join tbl_a as t1 on t0.user_id=t1.user_id
|
68
|
+
|
69
|
+
group by `user_id`;
|
70
|
+
|
71
|
+
```
|