Mysql 如何按月份名称按时间顺序而不是按字母顺序排序?
我想让月份名称按时间顺序而不是字母顺序排列。这是我的Sql代码Mysql 如何按月份名称按时间顺序而不是按字母顺序排序?,mysql,sql,spagobi,Mysql,Sql,Spagobi,我想让月份名称按时间顺序而不是字母顺序排列。这是我的Sql代码 select SUM(montant_ht)as Achat ,monthname(dim_date.date) as mois from operation_odoo join dim_date on operation_odoo.id_date_facturation = dim_date.id_date where (operation_odoo.id_type_op=1) and (dim_date.Annee= ?
select SUM(montant_ht)as Achat ,monthname(dim_date.date) as mois
from operation_odoo
join dim_date on operation_odoo.id_date_facturation = dim_date.id_date
where (operation_odoo.id_type_op=1) and (dim_date.Annee= ? or ? is null )
group by mois
你可以按月订购
select
SUM(montant_ht)as Achat
,monthname(dim_date.date) as mois
from operation_odoo
join dim_date on operation_odoo.id_date_facturation = dim_date.id_date
where (operation_odoo.id_type_op=1) and (dim_date.Annee= ? or ? is null )
group by mois
order by month(dim_date.date)
对于SpagoBI,请尝试将列month添加到查询中
select
SUM(montant_ht)as Achat
,monthname(dim_date.date) as mois
, month(dim_date.date)
from operation_odoo
join dim_date on operation_odoo.id_date_facturation = dim_date.id_date
where (operation_odoo.id_type_op=1) and (dim_date.Annee= ? or ? is null )
group by mois, month(dim_date.date)
order by month(dim_date.date)
你可以按月订购。我建议:
order by month(max(dim_date.date))
关于你的问题,我建议:
select monthname(d.date) as mois,
sum(o.montant_ht)as Achat
from operation_odoo o join
dim_date d
on o.id_date_facturation = d.id_date
where o.id_type_op = 1 and
( d.Annee= ? or ? is null )
group by mois
order by month(max(d.date));
在“选择查询”中,包括“月号”和“按月号排序”的附加列 确保您也在分组中包含相同的内容 示例查询:
select current_Date,DATE_FORMAT(current_date,'%b') as
m_name,DATE_FORMAT(current_date,'%m') as m_num
order by m_num
只需使用日历表中包含月号的列,将其添加到Group By,然后按其排序。旁注:您确定要单独按月分组而不考虑年份吗?感谢您的回答,但它在phpMyAdmin中显示了正确的结果,但在我的SpagoBI报告中,它按字母顺序显示。我不知道为什么要帮忙?