0

我有 2 列:
[tblCustomer] [tblInquiry] 我想返回所有客户(因此在本例中为 6 条记录)。此外,如果至少有 1 个 Inquiry 没有准备好(完成),则附加一个值为 [False] [result]的字段, 此 Query 返回 7 条记录: 这可能吗?如果是,我做错了什么? 提前致谢。
ID | DebtNr | CustomerName
1 | 10001 | CustomerNr001
2 | 10002 | CustomerNr002
3 | 10003 | CustomerNr003
4 | 10004 | CustomerNr0ab
5 | 10008 | CustomerNr0yy
6 | 10012 | CustomerSomeName


ID | CustID | IsInquiryReady
1 | 1 | True
2 | 1 | False
3 | 6 | True
4 | 2 | False




ID | DebtNr | CustomerName | IsAtLeastOneNotReady
1 | 10001 | CustomerNr001 | True
2 | 10002 | CustomerNr002 | True
3 | 10003 | CustomerNr003 | False
4 | 10004 | CustomerNr0ab | False
5 | 10008 | CustomerNr0yy | False
6 | 10012 | CustSomeName | False


SELECT [tblCustomer].ID, [tblCustomer].CustomerName, [tblCustomer].DebtNr, [tblInquiry].ID, [tblInquiry].IsInquiryReady FROM [tblCustomer] LEFT JOIN [tblInquiry] ON [tblInquiry].CustomerID = [tblCustomer].Id;



4

1 回答 1

1

你可以做类似的事情

select a.id, a.debtnr, a.customername,(select 'true' from dbo.tblinquiry b where b.custid = a.id and isinquiryready = 'false') as IsAtleastonenotready from dbo.tblcustomer a
于 2013-04-06T23:46:03.267 回答