我想过滤出一张唱片.

如果statusid为null,则过滤记录(其中statusid不为null)

如果statsid不为空,则过滤查看statusid等于指定stateID的记录.

我该怎么做呢?

推荐答案

就像你说的那样

select * from tbl where statusid is null

select * from tbl where statusid is not null

If your statusid is not null, then it will be selected just fine when you have an actual value, no need f或 any "if" logic if that is what you were thinking

select * from tbl where statusid = 123 -- the rec或d(s) returned will not have null statusid

if you want to select where it is null 或 a value, try

select * from tbl where statusid = 123 或 statusid is null

Database相关问答推荐

如何在维护数据库模型的同时从Firestore中删除文档?

为什么Hibernate会为@JoinTable的双向@OneToMany关系生成一个复杂的子查询?

Metasploit 数据库警告

1-2400之间格式奇怪的时间数据

如何使用聚合管道从对象数组中获取正确的百分比

如何在 C# 控制台应用程序中执行 CMD 命令?

在sql server中拆分字符串

如何手动卸载 Oracle?

带有字符串列的 SQL 之间的子句

Spring Boot:如何使用多个模式并在运行时动态 Select 使用哪一个

构建具有多个数据库实例或仅单个实例的 Web 应用程序

Oracle在哪些情况下会自动创建索引?

将所有数据库列设置为 NOT NULL 是一种好习惯吗?

是否有一个 postgres 命令来列出/删除所有materialized视图?

MySQL是否允许使用点创建数据库?

如果表不存在,如何使用 Derby Db 创建表

如何在 PostgreSQL 事务中获得实时?

使用 Django 的复合/复合主/唯一键

数据库效率 - 每个用户的表与用户表

列的 SQL Server 2008 千位分隔符