select 合同金额,项目名称,已付金额,运算结果
from
(
select 合同金额,项目名称,已付金额,
case when 条件1 then 运算结果1 else 0 end as flag1,
case when 条件2 then 运算结果2 else 0 end as flag2,
case when.... end as flag10 -- 筛选出这些项目下所有满足付款条件的记录
from tabname where 项目id in
(select distinct 项目id from tabname where 已付金额 < 合同金额)
)t -- 筛选出已付金额小于合同金额的项目
where flag1 <> 0 or flag2 <> 0 union all
select 合同金额,项目名称,已付金额,运算结果
from
(
select 合同金额,项目名称,已付金额,
case when 条件1 then 运算结果1 else 0 end as flag1,
case when 条件2 then 运算结果2 else 0 end as flag2,
case when.... end as flag10
from tabname where 项目id in
(select distinct 项目id from tabname where 已付金额 < 合同金额)
)t
where flag1 = 0 or flag2 = 0