参考如下:
select *
from (SELECT '本年累计' as type, 客户ID as 客户ID, sum(运货费) 运货费
FROM S订单 t
where 订购日期 like '${p_yf}' || '%'
group by 客户ID
union all
SELECT '近5年' as type, 客户ID as 客户ID, sum(运货费) 运货费
FROM S订单 t
where 订购日期 like '${left(p_yf,4)}' || '%'
group by 客户ID
union all
SELECT '历史累计' as type, 客户ID as 客户ID, sum(运货费) 运货费
FROM S订单 t
where 1 = 1
group by 客户ID) a
where a.type = '${type}'