sql - 检查包含所有空值的字段的多行事务
问题描述
我有一个事务表,其中完整的事务(tranid)根据下面的示例跨越多行
我要查找的是包含所有空值与仅部分具有空值的 tranid 的事务,并且仅显示 tranid 在 acount_id 下每列为空的情况,而在上面的示例中仅显示 6 个中的 2 个。
我编写了以下查询,但搜索“is null”只会产生第一笔交易中包含 null 的两行,而不是在整个交易中搜索所有 null。我不确定如何搜索,希望有人可以帮助解决这里的逻辑。
select *
from ns.tItemFulfillment itf
inner join ns.tsalesorder so on itf.created_from_id = so.transaction_id
left join ns.tpurchaseorder tpo on so.transaction_id = tpo.created_from_id
inner join ns.transaction_lines tl on itf.transaction_id = tl.transaction_id
left join ns.accounts a on tl.account_id = a.account_id
where tl.account_ID IS NULL and tpo.created_from_id is null
产生以下内容,如您所见,这只是上面事务的最后两行。
我应该只能查询带有所有空值的 tranid,这是我需要帮助的。谢谢
解决方案
使用聚合:
select tranid
from mytable —- or whatever join you need
group by tranid
having max(account_id) is null
and max(account_number) is null
—- etc for all columns that need to be all null
推荐阅读
- python - 使用 cx_Oracle 从 ref 游标中检索列名
- json - How to add Multiple Address space into a Azure Rm Virtual Network using JSON Templates
- angular - Angular 4获取输入值(timepicker)onBlur(focusOut)
- javascript - Chrome Extension has been crashing suddenly
- c# - How to synchronize a list of related entities .NET EF Core
- python - python3 中的 date-from-num 类似
- azure-service-fabric - `diagnosticsStore` 如何在独立服务结构中工作?
- haskell - Haskell错误我该如何解决
- android - 上传/下载文件 CloudRail Android/Dropbox
- c# - 使用 if 语句 c# 选择正确的列表