mysql - ORDER month TABLE by current month -
i want order months current month in final position.
i have subquery returns this:
+-----+-----------+ | 1 | monthname | +-----+-----------+ | 1 | jan | | 2 | feb | | 3 | mar | | 4 | apr | | ... | ... | +-----+-----------+
then want order current month (month(now())
) last value. keep getting default month order.
for example, today, in july (month n°7), have:
+-----+-----------+ | 1 | monthname | +-----+-----------+ | 8 | aug | | 9 | sep | | 10 | oct | | 11 | nov | | 12 | dec | | 1 | jan | | 2 | feb | | 3 | mar | | 4 | apr | | 5 | mei | | 6 | jun | | 7 | jul | +-----+-----------+
is possible in sql query? if so, best way proceed?
edit
my current query following
select `months`, ifnull(case_result.total_rows,0) results (select `one`,`monthname` months (select 1 `one`, 'january' `monthname` union select 2 `one`,'feburary' `monthname` union select 3 `one`, 'march' `monthname` union select 4 `one`, 'april' `monthname` union select 5 `one`, 'may' `monthname` union select 6 `one`,'june' `monthname` union select 7 `one`,'july' `monthname` union select 8 `one`, 'august' `monthname` union select 9 `one`, 'september' `monthname` union select 10 `one`, 'october' `monthname` union select 11 `one`, 'november' `monthname` union select 12 `one`, 'december' `monthname` order ) month_table) tempmonths left join (select month(date_surgery) `month`, count(id_cases) total_rows cases date_surgery between date_sub(now(), interval 11 month) , now() , cases.name = 'bone tumor' group month(`date_surgery`)) case_result on tempmonths.one = case_result.month
but part need order subquery
select 1 `one`, 'january' `monthname` union select 2 `one`,'feburary' `monthname` union select 3 `one`, 'march' `monthname` union select 4 `one`, 'april' `monthname` union select 5 `one`, 'may' `monthname` union select 6 `one`,'june' `monthname` union select 7 `one`,'july' `monthname` union select 8 `one`, 'august' `monthname` union select 9 `one`, 'september' `monthname` union select 10 `one`, 'october' `monthname` union select 11 `one`, 'november' `monthname` union select 12 `one`, 'december' `monthname` order ...
if one
name of column has month number, add select
statement:
order (one+11-month(now)) % 12
that expression 11 current month, , other months less because of modulo operator (%
).
Comments
Post a Comment