日期:2014-05-17 浏览次数:20492 次
create table #item(v1 int,v2 int ,price decimal(12,2))
insert into #item
select 0,200,1
union all select 200,500,1.5
union all select 500,1000,2
create table #tb(empl_no varchar(10),num int)
insert into #tb
select '001',300
union all select '002',100
union all select '003',600
union all select '002',800
union all select '003',100
union all select '001',500
union all select '003',800
select * from #item
select * from #tb
select empl_no,sum(salary) as salary
from (
select *,salary=(select top 1 price from #item b where a.num>=v1 and a.num<v2)
from #tb a
)t
group by empl_no
drop table #item,#tb
/*
empl_no salary
--------------------------
001 3.50
002 3.00
003 5.00
*/