开发者

how to count net amount according to month

开发者 https://www.devze.com 2023-01-09 19:30 出处:网络
SELECT EXTRACT(month from doc_date) columnno, sum(net_amt_rm) sum_amt, max(doc_date) ddate FROM POSM WHERE EXTRACT (year from doc_date) = \'2010\'

SELECT EXTRACT(month from doc_date) columnno, sum(net_amt_rm) sum_amt, max(doc_date) ddate

FROM POSM

WHERE EXTRACT (year from doc_date) = '2010'

GROUP BY EXTRACT(month from doc_date)

UNION //union no 2  
SELECT EXTRACT(month from doc_date) columnno, sum(net_amt_rm) sum_amt, max(doc_date) ddate  
FROM CIM  
WHERE EXTRACT(year from doc_date) = '2010'  
GROUP BY EXTRACT(month from doc_date)   

UNION  //union no3  
SELECT EXTRACT(month from doc_date) columnno, sum(net_amt_rm) sum_amt, max(doc_date) ddate  
FROM CAM  
WHERE EXTRACT(year from doc_date) = '2010'  
GROUP BY EXTRACT(month from doc_date)

the output for this query is like this:

columnno | sum amt | ddate  
3             6      01/march/2010  
7            250     29/july/2010 // output for union no2  
7           2617     02/july/2010 // output for union no3

but i want my output to be like this

columnno | sum amt | ddate  
3       开发者_运维技巧      6      march  
7            2867    july //output for union no 2 and 3 are sum together to get only one july

its means that total the amount in one month only


try this one

select columnno , sum(sum_amt), EXTRACT(month from ddate) ddate from 
<your query> 
group by columnno , (EXTRACT(month from ddate))
0

精彩评论

暂无评论...
验证码 换一张
取 消