回答編集履歴
2
コメントを頂いてクエリを追記
test
CHANGED
@@ -61,3 +61,85 @@
|
|
61
61
|
4 佐藤次郎 佐藤次郎 00011112222 00011112222 00011112222 00011112222
|
62
62
|
|
63
63
|
```
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
コメントを受けて考えたクエリ
|
68
|
+
|
69
|
+
```SQL
|
70
|
+
|
71
|
+
select
|
72
|
+
|
73
|
+
main_test.id as main_id,
|
74
|
+
|
75
|
+
sub_test.id as sub_id,
|
76
|
+
|
77
|
+
concat(
|
78
|
+
|
79
|
+
main_test.name1,
|
80
|
+
|
81
|
+
main_test.name2
|
82
|
+
|
83
|
+
) as main_name,
|
84
|
+
|
85
|
+
concat(
|
86
|
+
|
87
|
+
sub_test.name1,
|
88
|
+
|
89
|
+
sub_test.name2
|
90
|
+
|
91
|
+
) as sub_name,
|
92
|
+
|
93
|
+
concat(
|
94
|
+
|
95
|
+
main_test.h_phone1,
|
96
|
+
|
97
|
+
main_test.h_phone2,
|
98
|
+
|
99
|
+
main_test.h_phone3
|
100
|
+
|
101
|
+
) as main_h_phone,
|
102
|
+
|
103
|
+
concat(
|
104
|
+
|
105
|
+
sub_test.m_phone1,
|
106
|
+
|
107
|
+
sub_test.m_phone2,
|
108
|
+
|
109
|
+
sub_test.m_phone3
|
110
|
+
|
111
|
+
) as sub_m_phone,
|
112
|
+
|
113
|
+
concat(
|
114
|
+
|
115
|
+
sub_test.h_phone1,
|
116
|
+
|
117
|
+
sub_test.h_phone2,
|
118
|
+
|
119
|
+
sub_test.h_phone3
|
120
|
+
|
121
|
+
) as sub_h_phone,
|
122
|
+
|
123
|
+
concat(
|
124
|
+
|
125
|
+
main_test.m_phone1,
|
126
|
+
|
127
|
+
main_test.m_phone2,
|
128
|
+
|
129
|
+
main_test.m_phone3
|
130
|
+
|
131
|
+
) as main_m_phone
|
132
|
+
|
133
|
+
from test as main_test inner join test as sub_test
|
134
|
+
|
135
|
+
on (main_test.name1 = sub_test.name1 and main_test.name2 = sub_test.name2 and
|
136
|
+
|
137
|
+
( (main_test.h_phone1 = sub_test.m_phone1 and main_test.h_phone2 = sub_test.m_phone2 and main_test.h_phone3 = sub_test.m_phone3 ) or
|
138
|
+
|
139
|
+
(main_test.m_phone1 = sub_test.h_phone1 and main_test.m_phone2 = sub_test.h_phone2 and main_test.m_phone3 = sub_test.h_phone3 )
|
140
|
+
|
141
|
+
)
|
142
|
+
|
143
|
+
)
|
144
|
+
|
145
|
+
```
|
1
抽出結果に項目名を追加
test
CHANGED
@@ -34,7 +34,7 @@
|
|
34
34
|
|
35
35
|
|
36
36
|
|
37
|
-
最後に、提供されたテストデータに対して
|
37
|
+
最後に、提供されたテストデータに対してSQLを実行した結果を載せます。
|
38
38
|
|
39
39
|
|
40
40
|
|
@@ -44,18 +44,20 @@
|
|
44
44
|
|
45
45
|
```
|
46
46
|
|
47
|
-
|
47
|
+
id main_name sub_name main_h_phone sub_m_phone sub_h_phone main_m_phone
|
48
48
|
|
49
|
-
1
|
49
|
+
1 佐藤太郎 佐藤太郎 00011112222 00011112222 00011112222 00033334444
|
50
50
|
|
51
|
-
|
51
|
+
1 佐藤太郎 佐藤太郎 00011112222 00033334444 00033334444 00033334444
|
52
52
|
|
53
|
-
2
|
53
|
+
2 佐藤太郎 佐藤太郎 00011112222 00033334444 00011112222 00011112222
|
54
54
|
|
55
|
-
|
55
|
+
2 佐藤太郎 佐藤太郎 00011112222 00011112222 00011112222 00011112222
|
56
56
|
|
57
|
-
3
|
57
|
+
3 佐藤太郎 佐藤太郎 00033334444 00033334444 00011112222 00033334444
|
58
58
|
|
59
|
+
3 佐藤太郎 佐藤太郎 00033334444 00033334444 00033334444 00033334444
|
60
|
+
|
59
|
-
4
|
61
|
+
4 佐藤次郎 佐藤次郎 00011112222 00011112222 00011112222 00011112222
|
60
62
|
|
61
63
|
```
|