我需要为一个国家选择一个经过处理的行并且同一国家存在一个未处理的行。对于下表,我将返回带有id = 1
.
所以首先我需要检查是否有一行有TREATED
状态,然后我必须检查是否有一行有UNTREATED
状态并且与状态相同的国家TREATED
。
Table example 1
+----+--------+--------------+
| id | country| status |
+----+--------+--------------+
| 1 | SE | TREATED |
| 2 | DK | UNTREATED |
| 3 | SE | UNTREATED |
+----+--------+--------------+
Result of query
+----+--------+--------------+
| id | country| status |
+----+--------+--------------+
| 1 | SE | TREATED |
+----+--------+--------------+
如果不存在未处理的行或国家/地区不同,则我们不应返回任何内容
Table example 2
+----+--------+--------------+
| id | country| status |
+----+--------+--------------+
| 1 | SE | TREATED |
| 2 | DK | UNTREATED |
| 3 | US | UNTREATED |
+----+--------+--------------+
Result of query (empty)
+----+--------+--------------+
| id | country| status |
+----+--------+--------------+