这是我的查询的样子:
DECLARE @month date
DECLARE @CustomerId int
DECLARE @InterfacedSystemId int
SET @month = '2013-05-01'
SET @CustomerId = 24
SET @InterfacedSystemId = 1
SELECT * FROM
(
SELECT CONVERT(BIGINT,MisparHeshbonit) AS PreProcInvoiceNumber ,CONVERT(DATE,TaarichErech,103) AS PreProcDate , ROUND(sum(convert(float,SchumBruto)),2) AS PreProcSum
FROM [VisaCalCredit] VCC
WHERE CONVERT(DATE,TaarichErech,103) BETWEEN @month AND DATEADD(DAY,-1,DATEADD(MONTH,1,@month))
AND VCC.CustomerID = @CustomerID
GROUP BY MisparHeshbonit , CONVERT(DATE,TaarichErech,103)
) AS PreTable
ORDER BY PreProcInvoiceNumber, PreProcDate
SELECT * FROM
(
SELECT InvoiceNumber AS PostProcInvoiceNumber,ActualPaymentTime AS PostProcDate ,ROUND(sum(GrossAmount),2) AS PostProcSum
FROM [CreditAndDebit] C INNER JOIN [Transaction] T ON C.TransactionID = T.ID
WHERE ActualPaymentTime BETWEEN @month AND DATEADD(DAY,-1,DATEADD(MONTH,1,@month))
AND T.CustomerID = @CustomerId
AND T.InterfacedSystemID = 1
GROUP BY InvoiceNumber , ActualPaymentTime
) AS PostTable
ORDER BY PostProcInvoiceNumber ,PostProcDate
我需要在这些表中找到 PreProcSum 和 PostProcSum 之间的差异 - 我不能在内部表本身之间进行内部连接(触发其他问题)。
如何在此查询中定义的这两个表之间进行内部连接?