如图所示,有一个下拉框,叫做“下拉框_时间跨度”,它的值是12,6,3,1。然后我的查询中想要根据该下拉框的选择,而定具体使用哪张表。例如选择了12,那么使用usr_finereport.yl_jbxx_expense_tongji_12month_s007;选择了6,那么使用usr_finereport.yl_jbxx_expense_tongji_6month_s007,以此类推。想问下可以如图中这样写吗?经过测试,可以。
可以~
直接用if嵌套 或是Switch判断都行
select * from
${if(aa==12,"usr_finereport.yl_jbxx_expense_tongji_12month_s007",if(aa==6,"usr_finereport.yl_jbxx_expense_tongji_6month_s007",if(aa==3,"usr_finereport.yl_jbxx_expense_tongji_3month_s007","usr_finereport.yl_jbxx_expense_tongji_1month_s007")))}
SELECT *
FROM
${SWITCH(下拉框_时间跨度,'12个月',"12month_s007",'6个月',"6month_s007",'3个月',"3month_s007",'1个月',"1month_s007")}
可以,但是需要注意的是,下拉框需要有默认值,不然SQL语句会报错
你这个类似问题我都看过好几次了。。。