我的sql如下,时间参数输入格式为yyyy,想知道如果写能够参数选中今年,数据查询去年。
select
a.* from (
SELECT *,SUBSTR(ds,1,4) as year_1, cat_l2_code as code
FROM hyjt_jk_23product_performance_table_cm
) a
where 1=1
${if(len(date)=0,"","and a.year_1 = ('"+SUBSTITUTE(date,",","','")+"')")}
${if(len(date_code)=0,"","and a.year_1 = ('"+SUBSTITUTE((date_code-1),",","','")+"')")}
换个参数名称吧,不要用内置的函数的关键字做为参数名称
${if(len(date)=0,"","and a.year_1 = '"+YEARDELTA(date,-1)+"'")}
${if(len(date)=0,"","and a.year_1 = ('"+date-1+"')")}