请教:一条语句查出某段时间内的用户数和所有的费用
name, time,money
wsz,2011-01-10,50
wsz2,2011-01-20,10
wsz,2011-01-21,5
wsz,2011-02-10,20
wsz3,2011-02-15,10
------------
结果:
人数,费用,时间
2,65,2011-01
2,30,2011-02
------解决方案--------------------select count(*)name,sum(money),time
from tb
group time
------解决方案--------------------select count( distinct name),sum(money),time
from tb
group time
------解决方案--------------------如果数据库里time字段存储的类型为varchar就用上面的语句,如果是date类型就用date_format()转换:
SQL code
select count(*),sum(money),date_format(time,'%Y-%m') as timeline from <tbl_name> group by timeline