I want to combine different sums for different periods in a query
i use the following query to get a sum.
SELECT table1.BRS,
Sum(CASE WHEN table2.DATUM BETWEEN :van1 AND :tot1 THEN (DBBASIS-CRBASIS) ELSE (0) END)
FROM table1 INNER JOIN table2 ON (table1.id= table2.id)
WHERE table2.DATUM BETWEEN :van1 AND :tot1
group by BRS
and this works as itnented.
If i upgrade to a second sum
SELECT table1.BRS,
Sum(CASE WHEN table2.DATUM BETWEEN :van1 AND :tot1 THEN (DBBASIS-CRBASIS) ELSE (0) END),
Sum(CASE WHEN table2.DATUM BETWEEN :van2 AND :tot2 THEN (DBBASIS-CRBASIS) ELSE (0) END)
FROM table1 INNER JOIN table2 ON (table1.id= table2.id)
WHERE table2.DATUM BETWEEN :van1 AND :tot1 or table2.DATUM BETWEEN :van2 AND :tot2
group by BRS
I get a false positive with 2 duplicate columns, even if the data is different. The query uses the same Dates for the second sum. When i change the second Sum to a Max function, it uses the Second dates
How to combine the results of these 2 functions.
PS: Interbase cannot uses
Select * from (Select Sum from...) Join (Select Sum from...)