Hi, i have trouble with following sql-statement (trimmed):
SELECT nr,
(CASE WHEN
SUM(vkdtab.amount*liter)<>0 AND
jjjjmm BETWEEN 201001 and 201009
THEN SUM(net)/SUM(vkdtab.amount*liter)
ELSE 0 END) as return
FROM tab
GROUP BY 1,2,3
It should give me the amount/liter of items in a special timeframe, but I get the error: column return must be in group by
After I add that column: cannot group by aggregate column
.
This is functional, just without the timeframe:
CASE WHEN
SUM(vkdtab.amount*liter)<>0
THEN SUM(net)/SUM(vkdtab.amount*liter)
ELSE 0 END
How can I add the timeframe without getting an error?