在以下示例中,我每天获取总计。我需要获取与DPetAcNo相关的累计总数。
SELECT
DPetAcNo as AcNo,
SUM(DPetAmount) as PetTotal
FROM PettyDetail
WHERE DPetComCode='15'
and DPetLocCode='01'
and DPetDate=CONVERT(date,'20181113',111)
group by
DPetAcNo
答案 0 :(得分:0)
解决此问题的规范方法是:
SELECT DPetAcNo as AcNo, SUM(DPetAmount) as PetTotal,
SUM(SUM(DPetAmount)) OVER (ORDER BY DPetAcNo) as Running_PetTotal
FROM PettyDetail
WHERE DPetComCode = '15' AND
DPetLocCode = '01' AND
DPetDate = '20181113'
GROUP BY DPetAcNo;
如果这不能满足您的要求,那么您需要清楚什么不起作用以及您实际想要的结果集。