如题,例如我想要查询2016-04-20到2016-08-30期间 每一天的数据合
time num
2016-04-20 10
2016-04-20 20
2016-04-21 5
2016-04-21 6
. .
. .
. .
2016-08-30 30
查询出来就是
2016-04-20 30
2016-04-21 11
. .
. .
. .
2016-08-30 30
select time,sum(num) from table where time between startTme and endTime group by time ;
select time,sum(num) from table where time>=startTme and time<=endTime group by time ;
select time,sum(num) from table where time>=startTme and time<=endTime group by time order by time;
select time,sum(num) from table where time between startTme and endTime group by time ;
select time,sum(num) from table where time>=startTme and time<=endTime group by time ;
这俩个是对的 一楼别闹 sum() 求和 group by 分组
我前段时间做了一个类似的功能,就是查询一段时间内的数据汇总(按天区分),最后采用的是根据时间段(起始时间与结束时间间隔的天数),动态拼接select 1使用union链接,在与要查询的数据使用left join关联,没有数据的用0填充
select count(*)from table where 1=1 and time between startTme and endTime;