假设我们有以下数据库:
First_Id Second_Id Name
null 1 Durant
null 1 Kobe
1 2 Lebron
2 2 Dwight
1 3 Dirk
我们要以两列构成某些特定对的方式提取行:
(1,2),(1,3)
所以答案将等于:
First_Id Second_Id Name
1 2 Lebron
1 3 Dirk
这可以使用以下查询:
SELECT *
FROM PLAYERS
WHERE (First_Id, Second_Id) IN (VALUES (1,2), (1,3))
我想做的是找到First_Id
是null
的那些行,我该怎么办?
SELECT *
FROM PLAYERS
WHERE (First_Id, Second_Id) IN (VALUES (null,1),(1,2), (1,3))
所需的输出是:
First_Id Second_Id Name
null 1 Durant
null 1 Kobe
1 2 Lebron
1 3 Dirk
答案 0 :(得分:2)
为什么不直接使用等于和逻辑运算符。在特定情况下,它比您要执行的操作简单:
override def filter(filterFunc: Int => Boolean): IntList = this match {
case Empty => Empty
case Cons(head, tail) if filterFunc(head) => Cons(head, tail.filter(filterFunc))
case Cons(_, tail) => tail.filter(filterFunc)
}
答案 1 :(得分:0)
您可以在下面尝试-
SELECT *
FROM PLAYERS
WHERE (First_Id, Second_Id) IN ((1,2), (1,3)) or (First_Id is null and Second_Id=1)
答案 2 :(得分:0)
用于查找元组的IN标准不考虑空值。
但是这些空值可以合并为另一个值。例如,以0来查找(0,1)连音以获取空值:
SELECT *
FROM PLAYERS
WHERE (COALESCE(First_Id,0), Second_Id) IN ((0,1),(1,2),(1,3));
答案 3 :(得分:0)
Select *
from Players
where (First_Id in (1) or First_Id is Null )
and Second_Id in (1,2,3)
尝试一下。