【发布时间】:2016-08-25 09:25:06
【问题描述】:
我的客户提交的发票中每张都包含一些物品。我想计算已完成发票的数量(所有项目均由操作员检查)
样本数据:
invoiceNumber | ItemNumber | Status
a 1 Null
a 2 checked
a 3 Null
b 1 checked
b 5 checked
在上面的示例数据中,已完成发票的数量为 1,因为发票编号 “B” 中的所有项目都已检查,未完成发票的数量为 1,因为发票 “A”,仅选中一项。
我的尝试:
select count(distinct invoiceNumber) as total
from invoices
where status is not null
返回 2!我不应该计算第 2 行,因为第 1 行和第 3 行仍然为 Null。
【问题讨论】:
-
您使用的是哪个 DBMS?
-
指定预期结果(使用与表格数据相同的格式。)
-
预期结果不是记录集。我正在寻找“1”