一种可能的方法是使用相关子查询,例如:
select e.*, (select top 1 t.taxrate from taxrates t where t.to > e.salary order by t.to)
from employees e
或使用between
:
select e.*, (select top 1 t.taxrate from taxrates t where e.salary between t.to and t.from)
from employees e
或者,您可以通过left join
以下方式使用:
select e.*, t.taxrate
from employees e left join taxrates t on (e.salary between t.to and t.from)
请注意,MS Access无法在查询设计视图中表示这种类型的联接(即,具有“计算的”联接条件的联接,而不是相等字段值的联接),但这仍然是有效的SQL,可以由JET数据库引擎成功评估。
在以上所有情况中,我都假设您的表名为Employees
&TaxRates
,请将其更改为适合的值。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句