在我的数据库中,我有两个表:tblReceipts
和tblDisclosure
。一些商业细节:
以下查询旨在返回1和2的所有实例,但实际上并非如此。我没有记录,但我知道存在一个这样的实例。当我运行查询时,我收到了在参数Test
中输入数据的请求。如果我删除HAVING
子句,查询将正确返回所有记录。如何根据需要应用过滤器?
SELECT
Sum([DBSFee] + [MyFee]) AS Fee,
[Amount] + [Adjustment] AS Rec,
tblReceipts.ID,
[Fee] - [Rec] AS Test,
tblClient.ClientName,
tblClient.ClientID,
tblReceipts.Notes
FROM
(tblDisclosure
INNER JOIN tblReceipts ON tblDisclosure.ReceiptsLookup = tblReceipts.ID)
INNER JOIN tblClient ON tblReceipts.ClientLookup = tblClient.ClientID
GROUP BY
[Amount] + [Adjustment],
tblReceipts.ID,
tblClient.ClientName,
tblClient.ClientID,
tblReceipts.Notes
HAVING Test <> 0;
答案 0 :(得分:0)
尝试
Select Fee, Rec, ID, Test, ClientName, ClientID, Notes FROM (
SELECT Sum([DBSFee]+[MyFee]) AS Fee, [Amount]+[Adjustment] AS Rec, tblReceipts.ID, [Fee]-[Rec] AS Test, tblClient.ClientName, tblClient.ClientID, tblReceipts.Notes
FROM (tblDisclosure INNER JOIN tblReceipts ON tblDisclosure.ReceiptsLookup = tblReceipts.ID) INNER JOIN tblClient ON tblReceipts.ClientLookup = tblClient.ClientID
GROUP BY [Amount]+[Adjustment], tblReceipts.ID, tblClient.ClientName, tblClient.ClientID, tblReceipts.Notes) as T
WHERE Test<>0;