php+mysql 求根据时间范围 统计 某一指定参数下的数据的语句

php+ mysql 下 求根据时间范围 统计 某一指定参数下的数据的语句

如下的 一张 表里 想求 2015年1月 到2015年2 月 这个时间端内 a的 value剩余 以及b的剩余

uid user1 value time
1 a 12000 2015-1-1
2 b 4000 2015-1-2
3 a -3000 2015-1-3
4 a -600 2015-1-4
5 b 2000 2015-1-8

编程新手 ,很多东西不懂. 答题的朋友如果同时也知道怎么用PHP把这个表体现出来.我愿意出钱征求.同时求师傅PHP师傅一位.有意的朋友留一下联系方式

参考如下:

select user1,sum(value)balance
from UserValue表
where time between "2015-01-01" and "2015-02-01" + INTERVAL 1 MONTH
group by user1
;
--或者
select user1,sum(value)balance
from UserValue表
where DATE_FORMAT(time,"%Y-%m") between "2015-01" and "2015-02"
group by user1
;
--或者
select user1,sum(value)balance
from UserValue表
where DATE_FORMAT(time,"%Y-%c") between "2015-1" and "2015-2"
group by user1
;

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2016-01-01
select sum (value) from table where user1 ='a' and time >= '2015-1-1' and time <= '2015-2-1'

select sum (value) from table where user1 ='b' and time >= '2015-1-1' and time <= '2015-2-1'本回答被提问者和网友采纳
相似回答