同问 ,自己先把需求理清楚 [解决办法] Select *,分类结果=(Select top 1 fl From t_cashu as C Where C.lx1=J.lx1 And C.lx2=J.lx2 And C.JE>=J.JE1 And C.JE<=J.JE2 order by sx desc ) From t_jilu表 as J [解决办法]
如果数据条件满足2个参数表条件 如何取?
select a.人员编号 ,a.姓名,a.金额,a.类型1,a.类型2b.分类 as 分类结果 from 【数据表】 a outer apply(select top (1) x.分类 from 【参数表】 x where isnull(x.类型1,a.类型1)=a.类型1 and isnull(x.类型2,a.类型2) = a.类型2 and a.金额 between isnull(x.金额1,a.金额) and isnull(x.金额2,a.金额) order by x.类型1 desc ,x.类型1 desc ,x.金额1 desc ,x.金额2 desc ) b [解决办法] 12楼正解!