Sql 如何筛选列表值中不存在的条件

Sql 如何筛选列表值中不存在的条件,sql,postgresql,Sql,Postgresql,假设我有一个表country,该表有一列name来存储一个国家的名称 Table schema: Column Name | Datatype | Description ID | int | ID of the table name | varchar(255) | Name of the country, i.e: UK, US, China 现在,如果我有一个n个字符串值的列表作为要筛选的输入数据: i.e: Tokyo, Ja

假设我有一个表country,该表有一列name来存储一个国家的名称

Table schema: 
Column Name | Datatype     | Description
ID          | int          | ID of the table
name        | varchar(255) | Name of the country, i.e: UK, US, China
现在,如果我有一个n个字符串值的列表作为要筛选的输入数据:

i.e: Tokyo, Japan, US, New York, UK, London, India, China, etc
如何编写sql查询来过滤国家/地区表中不存在的所有值

i.e: I want to return Tokyo, NewYork, London. 

您提到需要过滤列名,我还没有对此进行测试,但请尝试一下(MySQL):


我可能误解了您的问题,您应该发布您的国家/地区表架构以了解更多详细信息。

您需要将您的输入(东京、日本、美国、纽约、英国、伦敦、印度、中国)转换为表。像这样的

With CTE AS (
SELECT 'Tokyo' as name UNION ALL 
SELECT 'Japan' UNION ALL 
SELECT 'US' UNION ALL 
SELECT 'New York' UNION ALL 
SELECT 'UK' UNION ALL 
SELECT 'London' UNION ALL 
SELECT 'India' UNION ALL 
SELECT 'China' 
)
select name from CTE 
LEFT JOIN country ON CTE.name=country.name
WHERE country.name is NULL

在Postgres中,您可以这样做:

select d.name from unnest(array['Japan', 'US', 'New York', 'UK', 'London', 'India', 'China']) d(name)
 left join country on country.name=d.name where country.name is null

但东京、纽约、伦敦都存在于你们的国家表中。Country表只存储国家名称(英国、美国、中国等)而不存储城市您的DMB不能同时是mysql和postgresql。这是哪一个?我使用了Postgres数据库,换句话说,你从csv字符串中提取城市(和拼写错误的国家),因为它们在国家中不存在?
select d.name from unnest(array['Japan', 'US', 'New York', 'UK', 'London', 'India', 'China']) d(name)
 left join country on country.name=d.name where country.name is null