SELECT comp_id,SUM(money) FROM TT WHERE MONTH(DATE)=4 GROUP BY comp_id
select sum(money) from table where mounth(data)=3;select sum(money) from table where month(data)=4 and comp_id=???;
select sum(money) from 有一张表 where comp_id=xxx and date between '2009-04-01' and '2009-04-30'上月的改为2009-03-01 到 2009-03-31 就行了。
SELECT A.comp_id,SUM(A.money),(SELECT SUM(MONEY) FROM TT WHERE A.comp_id=comp_id AND MOHTN(DATE)=MONTH(DATE)-1 ) FROM TT A WHERE MONTH(A.DATE)=4 GROUP BY A.comp_id
select sum(if(date between'2009-04-01'and'2009-04-30',money,0)) as 200904, sum(if(date < '2009-04-01',money,0)) as 200904之前 from 有一张表 where comp_id=xxx
where mounth(data)=3;select sum(money) from table
where month(data)=4 and comp_id=???;
from 有一张表
where comp_id=xxx
and date between '2009-04-01' and '2009-04-30'上月的改为2009-03-01 到 2009-03-31 就行了。
)
FROM TT A
WHERE MONTH(A.DATE)=4 GROUP BY A.comp_id
sum(if(date < '2009-04-01',money,0)) as 200904之前
from 有一张表
where comp_id=xxx