Subject | Re: Query returns invalid result |
---|---|
Author | Roman Rokytskyy |
Post date | 2004-10-08T14:21:41Z |
> The intention is to find out the difference between the count ofTry
> rows with P and the count of rows with X, filtered by various
> criteria such as a given DateSbm and/or AccountId.
> ...
> Any suggestions on a correct SQL statement?
SELECT
(SELECT COUNT(CPR1.CLAIMSTS)
FROM CLAIMSPAIDREVERSED CPR1 WHERE CPR1.DATESBM>=?
AND CPR1.DATESBM<=?
AND CPR1.CLAIMSTS='P'
AND CPR1.ACCOUNTID=?
) - (SELECT COUNT(CPR2.CLAIMSTS) FROM
CLAIMSPAIDREVERSED CPR2 WHERE CPR2.DATESBM>=?
AND CPR2.DATESBM<=?
AND CPR2.CLAIMSTS='X' AND CPR2.ACCOUNTID=?
)
FROM RDB$DATABASE
Roman