sql过滤不出来数据,求指导

image.png

场景如上:

场景如下:红框中如果是历史,则需要过滤车型(全部车型/某一个),开始日期,结束日期,班别(早班/晚班),

我的sql如下:

select 

*

from  t_contribution_value_count

 WHERE  1=1

${if(len(p_plant)=0,"  "," and factory_id="+p_plant)}

${if(p_type="历史" ,

if( and(p_car="全部车型",p_class="早班"),"  and  LEFT(created_time, 10) between '" +start_date +" ' and '"+end_date+"'  and date_format(created_time,'%H:%i:%s')  between '08:00:00'  and '18:00:00'  ",

if(and(p_car="全部车型",p_class="晚班"),"  and  LEFT(created_time, 10) between '" +start_date +" ' and '"+end_date+"'  and date_format(created_time,'%H:%i:%s') not between '08:00:00'  and '18:00:00'  ",

if(and(p_car!="全部车型",p_class="早班"),"  and  LEFT(created_time, 10) between '" +start_date +" ' and '"+end_date+"'  and date_format(created_time,'%H:%i:%s')  between '08:00:00'  and '18:00:00'   and vehicle_type= '"+p_car+"' ",

if(and(p_car!="全部车型",p_class="晚班"),"  and  LEFT(created_time, 10) between '" +start_date +" ' and '"+end_date+"'  and vehicle_type= '"+p_car+"' and date_format(created_time,'%H:%i:%s') not between '08:00:00'  and '18:00:00'  ",

"")))))}

FineReport yzm333277 发布于 2024-6-22 21:25
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共1回答
最佳回答
0
CovidLv3高级互助
发布于2024-6-22 21:56

sql不对:咋可以把created_time拆分成两段来查询(一段yyyy-mm-dd,一段hh:mm:ss)这SQL查不出来的。用case 把created_time先识别成早班,晚班再查询

select * from ( select *,(case when created_time>=created_time早班开始时间 and created_time<晚班开始时间 then '早班' else '晚班') p_class) A where……

  • 1关注人数
  • 98浏览人数
  • 最后回答于:2024-6-22 21:56
    请选择关闭问题的原因
    确定 取消
    返回顶部