季度查询

image.pngimage.png本季度的数据现在能根据传入的参数查出来,但是上一季度的怎么查询,上面的条件怎么让他往前推三个月,现在日期格式是202301、202212、202211这种的

FineReport yzmknhfW9631117 发布于 2023-1-16 14:02 (编辑于 2023-1-17 15:03)
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共3回答
最佳回答
0
快乐星光Lv5中级互助
发布于2023-1-16 14:53(编辑于 2023-1-16 15:08)

将sql转化以下,直接可以随便查询任何一季度数据:

select 年,季,sum(weigth) totalweigth from (

select 

    substr(report_date,1,4) 年,

    case when substr(report_date,5,6) between '01' and '03' then 1 

     when substr(report_date,5,6) between '04' and '06' then 2

when substr(report_date,5,6) between '07' and '09' then 3

when substr(report_date,5,6) between '10' and '12' then 4 end as 季,

report_date,weigth 

from eva_norm_report

/**

select '202201' report_date, 50 weigth

union all

select '202204' report_date, 60 weigth

union all

select '202207' report_date, 70 weigth

union all

select '202209' report_date, 40 weigth

union all

select '202210' report_date, 30 weigth

union all

select '202212' report_date, 80 weigth

) s

*/

-- where substr(report_date,1,4)='2022'

    ) ss

where 1=1

      -- and 季 = 2 

      -- and 年='2022'

group by 年,季

image.png

  • 快乐星光 快乐星光 回复 yzmknhfW9631117(提问者) 看修改答案
    2023-01-16 15:07 
  • yzmknhfW9631117 yzmknhfW9631117(提问者) 按照您这样写 如果我选择第一季度,但是我还有一个上一季度的字段,需要取上一年的10-12月份的数据怎么取?
    2023-01-16 15:11 
  • 快乐星光 快乐星光 回复 yzmknhfW9631117(提问者) 你的上一季度什么意思,是上年同比数据还是就是同年上一季度?还有的数据是想怎么展示:是同比数据放在一行还是多行展示?
    2023-01-16 15:23 
  • yzmknhfW9631117 yzmknhfW9631117(提问者) 回复 快乐星光 同年上一个季度的数据,列表已更新麻烦您看下,都是在一行 只是在不同列
    2023-01-17 15:04 
最佳回答
0
用户6NWif5139660Lv6资深互助
发布于2023-1-16 14:05(编辑于 2023-1-16 14:35)

04 -3 

06 -3

不用加单引号

如果选择得第一季度

年份减1

cf0aafbf6818595b148223d4c880426.png

最佳回答
0
用户80532932Lv4见习互助
发布于2023-1-16 14:20

可以通过将日期字段转换增加年份和季度两个字段,然后通过筛选年份和季度作为控件来进行查询相对应的季度数据

  • 4关注人数
  • 1217浏览人数
  • 最后回答于:2023-1-17 15:03
    请选择关闭问题的原因
    确定 取消
    返回顶部