select distinct CALMONTH as 年月
from "/BIC/OHZOP_MV01"
where CALMONTH<=${结束月份}
and CALMONTH>=${开始月份}
order by ${switch(年月,开始月份,"年月 asc",结束月份,"年月 desc",中间月份,"decode(年月,'中间月份',1,'结束月份',2,'开始月份',3)")}
中间月份,"decode(年月,'中间月份',1,'结束月份',2,'开始月份',3)"
这里是解码成UTF-8字符
手册解释地址https://help.fanruan.com/finereport/doc-view-813.html#29
按照你所写的SQL语句,应该是当选择中间月份时,以decode部分进行排序?