如何将一年的12个月全部展示

如今年只有1-3月份有数据。但是要求我不管选择哪一年,横坐标都是1-12个月。只能union和创建日期维度表两种方式吗? 好吧。。。。

image.png

FineReport 重庆一棵草 发布于 2023-3-30 17:14 (编辑于 2023-3-31 08:54)
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共5回答
最佳回答
0
linbodingLv6中级互助
发布于2023-3-30 17:15

如果有日期表,那就拿日期表去关联数据。如果没有,就写sql,弄出12个月份,关联数据

  • 重庆一棵草 重庆一棵草(提问者) 感谢
    2023-03-30 17:23 
  • 重庆一棵草 重庆一棵草(提问者) 我这个left 出来还是只有2个月 是哪里出问题了吗? select * from model_main_dict mmd where module =\'帆软\' 这个表里面存了1-12个月。但是数据表里面只有1-2月的数据
    2023-03-31 08:55 
  • linboding linboding 回复 重庆一棵草(提问者) 以日期表为主表,left join 数据表
    2023-03-31 11:25 
最佳回答
0
YmengLv5中级互助
发布于2023-3-30 17:17

sql写个维表

例:SELECT '1月' AS MONTH UNION ALL SELECT '2月' AS MONTH ......

最佳回答
0
CD20160914Lv8专家互助
发布于2023-3-30 17:18

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
qiqits1984Lv6中级互助
发布于2023-3-30 17:21

使用sql 生成12个月份 然后left 你的数据。

最佳回答
0
PILGRIMLv5初级互助
发布于2023-3-30 17:26

SQL 数据集月份使用这个试试:select* from(SELECT TO_CHAR ( ADD_MONTHS (to_date('${日期}','YYYY' ),-LEVEL+1),'MM') mon FROM dual CONNECT BY LEVEL < 13)

  • 用户wyWHk2642625 用户wyWHk2642625 有mysql的吗
    2023-03-30 17:45 
  • PILGRIM PILGRIM 回复 用户wyWHk2642625 我常用Oracle,Mysql的给你在百度文库找了个例子,你看下可不可用:https://wenku.baidu.com/view/be0aa24224d3240c844769eae009581b6bd9bdf6.html?_wkts_=1680224319833&bdQuery=mysql%E6%9F%A5%E8%AF%A21%E5%88%B012%E6%9C%88%E4%BB%BD%E6%95%B0%E6%8D%AE
    2023-03-31 09:00 
  • 6关注人数
  • 347浏览人数
  • 最后回答于:2023-3-31 08:54
    请选择关闭问题的原因
    确定 取消
    返回顶部