无法让它发挥作用......这是我到目前为止所得到的:
SELECT CardCode, (sum(DocRate) DocRate/DocRate.Length)
FROM OPCH
WHERE DocRate > 1
AND DocStatus = 'O'
AND DocDate >= '20140101'
GROUP BY CardCode
尝试获取DocRate的总和(每行不同)并将其除以行数(得到平均值)。
这不起作用。
答案 0 :(得分:2)
很容易,找到解决方案。
使用AVG()
。
我的代码:
SELECT CardCode,
avg(DocRate) DocRate
FROM OPCH
WHERE DocRate > 1
AND DocStatus = 'O'
AND DocDate >= '20140101'
GROUP BY CardCode
答案 1 :(得分:1)
尝试使用子查询。
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