你这个得判断
select * from 表 where 1=1 ${if(len(sql("数据连接", "select date from 表 where date = '"+参数+"' " ,1 )) = 0 , " and date =select max(date) from 表 " , "and date ='"+参数+"'") }
大概这么个道理
--------------
and 1=1 ${if(len(月份)==0,"",
if(len(sql("数据连接","select distinct audit_yf from fr_problem_write where audit_yf = '"+月份+"'",1,1)) == 0 ,
" and audit_yf = (select max(audit_yf) from fr_problem_write limit 0,1) ",
" and audit_yf = '"+月份+"'"
))}
之前写过个类似的, 是mysql的你参考一下; 月份参数有数据的查询,没有的查询最近月份