Try creating query like this
select x.* from (
select '1' as inum,sum(T1.TB_STATS_ROWS_WRITE) as first_write,sum(T1.TB_STATS_ROWS_READ) as first_read,
T1.TB_STATS_TABLE,T1.TB_STAT_DBNAME,T1.TB_STATS_SC HEMA
from TB_STATS_HISTORY T1
where
month(T1.TB_STAT_TS) = month(current date - 1 month)
and day(T1.TB_STAT_TS) between 1 and 7
group by T1.TB_STATS_TABLE,T1.TB_STAT_DBNAME,T1.TB_STATS_SC HEMA
Union all
select '2' as inum,sum(T1.TB_STATS_ROWS_WRITE) as first_write,sum(T1.TB_STATS_ROWS_READ) as second_read,
T1.TB_STATS_TABLE,T1.TB_STAT_DBNAME,T1.TB_STATS_SC HEMA
from TB_STATS_HISTORY T1
where
month(T1.TB_STAT_TS) = month(current date - 1 month)
and day(T1.TB_STAT_TS) between 1 and 7
group by T1.TB_STATS_TABLE,T1.TB_STAT_DBNAME,T1.TB_STATS_SC HEMA
) as x
order by x.inum,x.TB_STAT_DBNAME";
I hope this helps
I created the temporary table and dumped the values in the temporary table and sorted the values.
Regards
Rajesh Krishnan