假设我有 5 行,包含以下内容:
ID KEY VALUE
1 address 123 Main Street
1 latlng (111.139, 111.238)
2 address 45 South Street
3 address 67 North Ave
3 latlng (448.002, 100.301110)
现在,如果我想只返回不包含相应 latlng 行的行来伴随地址(即 ID 2),我将如何使用 mySQL 语句来做到这一点?
这个让我难倒了!!
SELECT *
FROM TABLE
WHERE ID NOT IN
(SELECT ID FROM TABLE WHERE KEY = 'LATLNG')
尝试类似
SELECT t1.*
FROM Table t1
LEFT OUTER JOIN Table t2 ON t1.id = t2.id
WHERE t1.Key = 'latlng' AND t2.Key = 'address' AND t2.id IS NULL