Well easy enough, found the solution.
Using AVG()
.
My code:
SELECT CardCode,
avg(DocRate) DocRate
FROM OPCH
WHERE DocRate > 1
AND DocStatus = 'O'
AND DocDate >= '20140101'
GROUP BY CardCode
Frage
Can't get it to work... this is what I got so far:
SELECT CardCode, (sum(DocRate) DocRate/DocRate.Length)
FROM OPCH
WHERE DocRate > 1
AND DocStatus = 'O'
AND DocDate >= '20140101'
GROUP BY CardCode
Trying to get the sum of DocRate (which is diffrent each row) and divide it with number of rows (to get an average).
This isn't working.
Lösung
Well easy enough, found the solution.
Using AVG()
.
My code:
SELECT CardCode,
avg(DocRate) DocRate
FROM OPCH
WHERE DocRate > 1
AND DocStatus = 'O'
AND DocDate >= '20140101'
GROUP BY CardCode
Andere Tipps
Try using sub query.
SELECT CardCode, (DocRate/length)
FROM
(SELECT CardCode,sum(DocRate) DocRate, sum (DocRate.Length) length
FROM OPCH
WHERE DocRate > 1
AND DocStatus = 'O'
AND DocDate >= '20140101'
GROUP BY CardCode) doc
GROUP BY CardCode