-1
我正在使用此查詢,但出現錯誤vdagbk.bedrag
和vdagbk.reden
。表列在查詢中不可查表
問題是,如果我在第二個SELECT中輸入,結果肯定會是錯誤的,因爲表中的double數據會將結果總結多次。
SELECT TOP (100) PERCENT
SUM(P.bedrag) AS ex,
C.dosno,
C.dosnm,
SUM(P.betaald) AS TotBetaald,
SUM(CASE vdagbk.reden WHEN 'H' THEN vdagbk.bedrag END) AS Expr1
FROM
dbo.verkopen AS P
INNER JOIN
(SELECT DISTINCT
dbo.doss.dosno, dbo.doss.dosnm, dbo.verkopen.ino
FROM dbo.verkopen
INNER JOIN dbo.doss ON dbo.verkopen.ino = dbo.doss.ino
INNER JOIN dbo.vdagbk ON dbo.verkopen.ino = dbo.vdagbk.ino
WHERE
(dbo.doss.uitvoerder LIKE 'LL')
AND (dbo.doss.dosno LIKE '101520')
GROUP BY
dbo.doss.dosno, dbo.doss.dosnm, dbo.verkopen.ino) AS C ON C.ino = P.ino
INNER JOIN
dbo.vdagbk AS vdagbk_1 ON P.ino = vdagbk_1.ino
GROUP BY
C.dosno, C.dosnm
如何使這個查詢工作?