如何过滤SQL中两个列表的任意组合?
假设我有列表1(1,2,3,4,5,6,7,8,9)和列表2('a','b','c','d')) 如何筛选出column1同时等于list1中的任何值和column2同时等于list2中的任何值的行 比如:如何过滤SQL中两个列表的任意组合?,sql,amazon-athena,Sql,Amazon Athena,假设我有列表1(1,2,3,4,5,6,7,8,9)和列表2('a','b','c','d')) 如何筛选出column1同时等于list1中的任何值和column2同时等于list2中的任何值的行 比如: select * from table1 where (column1 not in (1,2,3,4,5,6,7,8,9) and column2 not in ('a','b','c','d')) or (column1 in (1,2,3,4,5,6,7,8,9) and column
select * from table1
where (column1 not in (1,2,3,4,5,6,7,8,9) and column2 not in ('a','b','c','d'))
or (column1 in (1,2,3,4,5,6,7,8,9) and column2 not in ('a','b','c','d'))
or (column1 not in (1,2,3,4,5,6,7,8,9) and column2 in ('a','b','c','d'))
这在亚马逊雅典娜行得通
谢谢
筛选出column1等于list1和list1中任何值的行
第2列等于列表2中的任何值
这意味着:
select * from table1
where (column1 not in (1,2,3,4,5,6,7,8,9) and column2 not in ('a','b','c','d'))
select * from table1
where (column1 not in (1,2,3,4,5,6,7,8,9) or column2 not in ('a','b','c','d'))
编辑 当column1在list1中有值时,如果column2有值,则过滤掉此行 列表2中的值
这意味着:
select * from table1
where (column1 not in (1,2,3,4,5,6,7,8,9) and column2 not in ('a','b','c','d'))
select * from table1
where (column1 not in (1,2,3,4,5,6,7,8,9) or column2 not in ('a','b','c','d'))
您的第二个查询将使用
或
而不是和
——尽管它也会删除重复项。