Sql 如何查找丢失的数据
我必须找到保险单上缺少的riskunits.DescriptionSql 如何查找丢失的数据,sql,Sql,我必须找到保险单上缺少的riskunits.Description 我可以在policyid上匹配riskunitid,但如何找到没有riskunit.description的策略?我不熟悉SQL不知道您的确切表结构,我们只能使用一些伪代码: select * from policy p where not exists ( select * from riskunit r where r.policyid = p.policyid ) 这将查找没有riskunit记录的保单。如
我可以在policyid上匹配riskunitid,但如何找到没有riskunit.description的策略?我不熟悉SQL不知道您的确切表结构,我们只能使用一些伪代码:
select *
from policy p
where not exists (
select *
from riskunit r
where r.policyid = p.policyid
)
这将查找没有riskunit记录的保单。如果您希望始终存在riskunit记录,但描述可能为null或空字符串,请改为:
select *
from policy p
join riskunit r
on r.policyid = p.policyid
where (r.description is null or r.description = '')
似乎遗漏了一些细节。就像您的表的定义一样。和示例数据。寻求帮助的问题必须包括期望的行为、特定的问题或错误以及在问题本身中重现这些问题所需的最短代码。没有明确问题陈述的问题对其他读者没有用处。请参阅:。请首先告诉我们您正在使用的DBMS,然后添加表定义。