you can use the WITH ROLLUP
in the group by to achieve multi level aggregation. try something like this SQL Fiddle
;WITH table1create astable table1
(
SELECT GETDATE() register_time,10 date,registered
UNION ALLint
SELECT);
insert GETDATEinto table1 values('2015/03/31',10);
insert register_timeinto table1 values('2015/03/31',20 registered);
UNIONinsert ALLinto
SELECTtable1 GETDATEvalues()-2 register_time'2015/03/21',30 registered);
UNIONinsert ALLinto
SELECTtable1 GETDATEvalues()-2 register_time'2015/02/01',15 registered);
UNIONinsert ALLinto
SELECTtable1 GETDATEvalues()+10 register_time'2015/02/01',1 registered);
UNIONinsert ALLinto
SELECTtable1 GETDATEvalues()+10 register_time'2015/02/02',25 registered);
UNIONinsert ALLinto
SELECTtable1 GETDATEvalues()+50 register_time'2015/01/31',11 registered
);
SELECT MONTH(ds.register_time) Month,DAY(ds.register_time) day,SUM(registered) AS totalOftheDay
FROM table1 ds
WHERE ds.register_time BETWEEN '2015-03-01 00:00:00' AND '2015-12-30 23:59:59'
GROUP BY MONTH(ds.register_time),DAY(ds.register_time) WITH ROLLUP