質問編集履歴
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -153,3 +153,35 @@
|
|
153
153
|
|
154
154
|
|
155
155
|
mysql 5.7
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
### 追記 ①+②ー③までをサブクエリを利用して作成できました。ここからマイナス分を削除しようと思います。
|
162
|
+
|
163
|
+
```
|
164
|
+
|
165
|
+
SELECT *
|
166
|
+
|
167
|
+
FROM t_transactions
|
168
|
+
|
169
|
+
WHERE t_transactions.id = (
|
170
|
+
|
171
|
+
SELECT MAX(id)
|
172
|
+
|
173
|
+
FROM t_transactions AS tmp
|
174
|
+
|
175
|
+
WHERE t_transactions.tran_grp = tmp.tran_grp
|
176
|
+
|
177
|
+
)
|
178
|
+
|
179
|
+
or settle_grp IS not null
|
180
|
+
|
181
|
+
and id NOT IN (
|
182
|
+
|
183
|
+
select settle_grp from t_transactions where settle_grp IS NOT NULL group by settle_grp
|
184
|
+
|
185
|
+
);
|
186
|
+
|
187
|
+
```
|
1
エラーメッセージを追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -118,17 +118,31 @@
|
|
118
118
|
|
119
119
|
### 試したこと
|
120
120
|
|
121
|
-
SQLを分割して、InnerJoinでつなげようと思いましたが
|
121
|
+
SQLを分割して、InnerJoinでつなげようと思いましたが下記エラーがでてしまいました。
|
122
122
|
|
123
123
|
どうぞよろしくお願いいたします。
|
124
124
|
|
125
125
|
```MySQL
|
126
126
|
|
127
|
+
#①+②
|
128
|
+
|
129
|
+
|
130
|
+
|
127
131
|
SELECT MAX(id) AS `id` from t_transactions group by tran_grp AS join1
|
128
132
|
|
129
|
-
INNER JOIN select id from t_transactions where settle_grp IS not null AS join2
|
133
|
+
INNER JOIN select `id` from t_transactions where settle_grp IS not null AS join2
|
130
134
|
|
131
135
|
ON join2.id = join1.id;
|
136
|
+
|
137
|
+
```
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
### 発生している問題・エラーメッセージ
|
142
|
+
|
143
|
+
```
|
144
|
+
|
145
|
+
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS join1 INNER JOIN select `id` from t_transactions where settle_grp IS not null' at line 1
|
132
146
|
|
133
147
|
```
|
134
148
|
|