你得有一个日期维度的表,用日期维度表关联业务表就行了! 类似
with a as (
select '1月' month_code,1 as month_number
union all
select '2月',2
union all
select '3月',3
union all
select '4月',4
union all
select '5月',5
union all
select '6月',6
union all
select '7月',7
union all
select '8月',8
union all
select '9月',9
union all
select '10月',10
union all
select '11月',11
union all
select '12月',12
)
select a.month_code,b.* from a left join (SELECT month_code,/*业务月份*/ amount from 订单表 ) b on a.month_code=b.month_code order by a.month_number/*排序用的*/
|