检查null或空

cvxl0en2  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(215)

我有这张table:

ID   Item.  Price.  Rating  Location
-------------------------------------
1    abc     2               xyz
2.   milk   10        7
3.   rose                    qqq
4.   DVD    10        2        
5.   WQQ     5

我要把所有项目的结果输出成好的或坏的,好的项目是其中的价格和位置列不为null或空。
输出

Good  Bad
1     4

如何在单个查询中做到这一点?

mwngjboj

mwngjboj1#

用下列方法尝试 case 表情。这是演示。

select
  sum(case when price is not null and location is not null then 1 else 0 end) as good,
  sum(case when price is null or location is null then 1 else 0 end) as bad
from yourTable

输出:

| good | bad |
| ---- | --- |
| 1    | 4   |

相关问题