一楼的想法应该是这个
因为SQL执行顺序的原因,所以你需要嵌套一层子查询
-----------------------------------------------
select t.* from (
select
a.cpi_id,a.inspecttime,a.INSPECTIONTYPEID,a.product_date,a.team_id,a.remark,a.MATERIAL_ID,a.inspect_num,b.NAME,
d.max,d.min,d.avg,d.sd,d.cv,d.over_num,e.name AS name2,e.id,
(case d.PARAMETERID when 10524200 then 1
when 300323 then 2
when 300320 then 3
when 300322 then 4
when 300326 then 5
when 10524202 then 6
when 300321 then 7
end ) as SEQ,
(case a.remark when \'.1\' then \'硬1#\'
when .2 then \'硬2#\'
when .3 then \'硬3#\'
when .4 then \'硬4#\'
when .5 then \'硬5#\'
when .6 then \'硬6#\'
when .7 then \'硬7#\'
when .8 then \'硬8#\'
when .9 then \'硬9#\'
when .10 then \'硬10#\'
when .11 then \'硬11#\'
when .12 then \'硬12#\'
when 01 then \'软1#\'
when 02 then \'软2#\'
when 03 then \'软3#\'
when 04 then \'软4#\'
when 05 then \'软5#\'
when 06 then \'软6#\'
when 07 then \'软7#\'
when 08 then \'软8#\'
when 09 then \'软9#\'
when 10 then \'软10#\'
else \'其它\' end) as machinename
FROM QUA.CIGARETTE_PHYS_SCENE a, PUB.EQUIPMENT b, QUA.CIGARETTE_PHYS_SCENE_PARA d, PUB.LOGICPARAMETER e
WHERE 1=1
${if(len(班次) == 0,\"\",\"and a.team_id = \'\" +班次 + \"\'\")} and 1=1
${if(len(类型) == 0,\"\",\"and a.INSPECTIONTYPEID = \'\" +类型 + \"\'\")} and 1=1
${if(len(牌号) == 0,\"\",\"and a.MATERIAL_ID = \'\" +牌号 + \"\'\")} and 1=1
${if(len(ID) == 0,\"\",\"and a.cpi_id = \'\" +ID + \"\'\")} and a.EQUIPMENT_ID=b.id
AND d.PARAMETERID=e.id and a.cpi_id=d.cpi_id and a.inspect_num=\'20\'
) t
where 1 = 1
${if(len(机台) == 0,\"\",\"and t.seq = \'\" +机台 + \"\'\")} and 1=1
order by t.INSPECTTIME DESC