mysql - SQL order by month DESC and year ASC -
i have sql query:
select * `billing` source = 'voip' group month(timestamp), year(timestamp) order month(timestamp) desc, year(timestamp) asc
the above query returning order:
2014-12-01 2014-11-01 2014-10-01 2015-05-01 2015-04-01 2015-03-01 2015-02-01 2015-01-01
i want order so:
2015-05-01 2015-04-01 2015-03-01 2015-02-01 2015-01-01 2014-12-01 2014-11-01 2014-10-01
how ordering date in descending order?
select * `billing` source = 'voip' group month(timestamp), year(timestamp) order min(timestamp) desc;
note: should never use select *
group by
. should explicitly select columns want, along aggregation functions. like:
select month(timestamp), year(timestamp), count(*) `billing` source = 'voip' group month(timestamp), year(timestamp) order min(timestamp) desc;
(this gets number of records each month.)
Comments
Post a Comment