动态切换年月日查询报表问题

语句如下:

select ResultFile as '品种',BatchId as '批号',TestEnv as '测试状态',count(1) as '测试总量'

,count(case when  Result=1 then 1 end ) as '合格量'

,convert(decimal(18,4),(count(case when  Result=1 then 1 end) / (count(1)+0.0))) as '总良率'

,convert(decimal(18,4),(count(case when  IthResult=1 then 1 end) / (count(1)+0.0))) as ' Ith良率'

,convert(decimal(18,4),(count(case when  PfResult=1 then 1 end) / (count(1)+0.0))) as ' Pf良率'

,convert(decimal(18,4),(count(case when  SEResult=1 then 1 end) / (count(1)+0.0))) as ' SE良率'

,convert(decimal(18,4),(count(case when  RsResult=1 then 1 end) / (count(1)+0.0))) as ' Rs良率'

,convert(decimal(18,4),(count(case when  VfResult=1 then 1 end) / (count(1)+0.0))) as ' Vf良率'

,0 as 'Im良率',0 as 'Idk判定'

,convert(decimal(18,4),(count(case when  KinkResult=1 then 1 end) / (count(1)+0.0))) as ' Kink良率'

,convert(decimal(18,4),(count(case when  LostResult=1 then 1 end) / (count(1)+0.0))) as ' SE_Lost良率'

,convert(decimal(18,4),(count(case when  bSm0=1 then 1 end) / (count(1)+0.0))) as ' SMSR0良率'

,convert(decimal(18,4),(count(case when  bSm1=1 then 1 end) / (count(1)+0.0))) as ' SMSR1良率'

,0 as 'SMSR2良率'

,convert(decimal(18,4),(count(case when  bWd=1 then 1 end) / (count(1)+0.0))) as ' WavDiff良率'

,convert(decimal(18,4),(count(case when  PbResult=1 then 1 end) / (count(1)+0.0))) as ' Stop_band良率'

From CHIP_TEST

where 1=1

group by ResultFile,BatchId,TestEnv

参数条件如下:

${if(type=="日报"," and date(TesTime )='"+ date +"'", 

if(type=="月报"," and strftime('%m',CHIP_TEST.TesTime )='"+ month+"'"+" and strftime('%Y',CHIP_TEST.

TesTime )='"+ year+"'"," and strftime('%Y',CHIP_TEST.TesTime )='"+ year+"'"))} 

参数不论放 1=1 后面 还是放group by 后面 都报错1=1 后面报 strftime 不存在函数group by  报错  and 错误

image.pngimage.png

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

什么数据库 没得这个函数 

image.png

--------------------------

image.png

  • six28 six28(提问者) https://help.fanruan.com/finereport/doc-view-408.html 官方给的哦
    2022-09-23 10:28 
  • six28 six28(提问者) SQL
    2022-09-23 10:29 
  • Z4u3z1 Z4u3z1 回复 six28(提问者) ms sqlserve?mysql?oracle等等都是SQL.......
    2022-09-23 10:31 
  • six28 six28(提问者) 回复 Z4u3z1 MS SQL
    2022-09-23 10:37 
  • Z4u3z1 Z4u3z1 回复 six28(提问者) strftime(\'%m\',CHIP_TEST.TesTime ) 改成 DATEPART(MONTH,CHIP_TEST.TesTime)
    2022-09-23 10:41 
最佳回答
0
格调Lv6初级互助
发布于2022-9-23 10:29

sql中用switch函数即可

  • 2关注人数
  • 396浏览人数
  • 最后回答于:2022-9-23 10:41
    请选择关闭问题的原因
    确定 取消
    返回顶部