Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Sum the distinct docid's

$
0
0
select distinct
gt.docid,
gt.act_id,
Sum(gt.gm_amt) amt
from gtemp gt
WHERE gt.gm_amt != '0' AND
docid IN ('12343','436220','asde32','641154','frd456')
Group BY
gt.docid,
gt.act_id

These are the actual results
docid act_id amt
12343 2115 -619.31
12343 2115 -2.77
12343 2115 2.77
12343 2115 619.31
436220 2115 -28
436220 2115 28
asde32 2115 -2876.16
641154 2115 -24315.62
frd456 2115 315.62

But after I sum and and say amt not equal to 0 I have to get only last 3 records which are asde32,641154,frd456 but my results are something like this
docid act_id amt
12343 2115 0
12343 2115 0
12343 2115 0
12343 2115 0
436220 2115 0
436220 2115 0
asde32 2115 0
641154 2115 0
frd456 2115 0

Viewing all articles
Browse latest Browse all 13329

Trending Articles