如图,查询出1-12月的数据,虽然只有3,4,5月有数据,但是想让其他月份也显示出来怎么弄

rrr.jpg

FineReport LBJ23 发布于 2023-11-9 19:25
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
1
CD20160914Lv8专家互助
发布于2023-11-9 20:09(编辑于 2023-11-9 20:11)

你在数据集里面用一个月份表去关联业务数据表就行了。这样就可以展示出来其它月份了

建议做一个月份维度的表,这样用表关联就行了!,而且方便后期所有业务表来使用

比如类似这样oracel数据库里面:

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/*排序用的*/

最佳回答
0
大林3143511Lv5中级互助
发布于2023-11-10 08:08

1楼大神的方法很不错,我记得还有个给空值赋0的语句来着,也能实现,可以上传下模板,一起研究下!

  • 2关注人数
  • 262浏览人数
  • 最后回答于:2023-11-10 08:08
    请选择关闭问题的原因
    确定 取消
    返回顶部