34,576
社区成员
发帖
与我相关
我的任务
分享
declare @tab table(f_item1 float,f_item2 float,f_career int,f_score float,f_no int)
insert into @tab(f_item1,f_item2,f_career,f_score,f_no)
select 75,70,303,145,1 union all
select 65,74,303,139,2 union all
select 68,69.5,303,137.5,3 union all
select 66.5,65,303,131.5,4 union all
select 68.5,62.5,303,131,5 union all
select 66.5,64.5,303,131,6 union all
select 65.5,65.5,303,131,7 union all
select 65.5,65,303,130.5,8 union all
select 74,66,304,140,1 union all
select 75.5,63.5,304,139,2 union all
select 71.5,65.5,304,137,3 union all
select 68,63.5,304,131.5,4 union all
select 65.5,66,304,131.5,5 union all
select 63,68.5,304,131.5,6 union all
select 67.5,63,304,130.5,7
declare @tab2 table(f_career int,f_plan int)
insert into @tab2(f_career,f_plan)
select 303,2 union
select 304,1
select a.f_item1,a.f_item2,a.f_career,a.f_score,a.f_no,case when a.f_no <= b.f_plan * 3 then 1 else 0 end as f_in
from @tab as a
inner join
@tab2 as b
on a.f_career = b.f_career
f_item1 f_item2 f_career f_score f_no f_in
75 70 303 145 1 1
65 74 303 139 2 1
68 69.5 303 137.5 3 1
66.5 65 303 131.5 4 1
68.5 62.5 303 131 5 1
66.5 64.5 303 131 6 1
65.5 65.5 303 131 7 0
65.5 65 303 130.5 8 0
74 66 304 140 1 1
75.5 63.5 304 139 2 1
71.5 65.5 304 137 3 1
68 63.5 304 131.5 4 0
65.5 66 304 131.5 5 0
63 68.5 304 131.5 6 0
67.5 63 304 130.5 7 0
[Quote=引用 6 楼 llxlett 的回复:]
SQL code
declare @t1 table(科目1 float,科目2 float,职位代码 int,分数 float,名次 int)
insert @t1
select 75, 70, 303, 145, 1 union all
select 65, 74, 303, 139 , 2 union all
select 68, 69.5 , 303, 137.5, 3 union all
select 66.5, 65 , 303 , 131.5 , 4 union all
select 68.5, 62.5 , 303, 131, 5 union all
select 66.5, 64.5 , 303, 131, 6 union all
sel…
[/Quote]
declare @t1 table(科目1 float,科目2 float,职位代码 int,分数 float,名次 int)
insert @t1
select 75, 70, 303, 145, 1 union all
select 65, 74, 303, 139 , 2 union all
select 68, 69.5 , 303, 137.5, 3 union all
select 66.5, 65 , 303 , 131.5 , 4 union all
select 68.5, 62.5 , 303, 131, 5 union all
select 66.5, 64.5 , 303, 131, 6 union all
select 65.5 , 65.5 , 303, 131, 7 union all
select 65.5, 65 , 303 , 130.5 , 8 union all
select 74 , 66 , 304, 140 , 1 union all
select 75.5, 63.5 , 304, 139 , 2 union all
select 71.5 , 65.5 , 304, 137, 3 union all
select 68 , 63.5 , 304, 131.5 , 4 union all
select 65.5, 66, 304, 131.5, 5 union all
select 63 , 68.5, 304, 131.5, 6 union all
select 67.5, 63, 304 , 130.5, 7
declare @t2 table(职位代码 int,计划数 int)
insert into @t2
select 303, 2 union all
select 304, 1
select a.*,是否进入第二轮考试=(case when a.名次<= b.计划数*3 then '1' else '' end)
from @t1 a join @t2 b
on a.职位代码=b.职位代码
select t1.* ,是否进入第二轮考试=case when 名次<=计划数*3 then '1' else '' end
from t1,t2 where t1.职位代码=t2.职位代码
--就和楼上的一样 用一个JOIN搞定
select a.*,[是否进入第二轮考试]=(case when a.名次<=b.计划数*3 then '1' else '' end)
from tb1 a join tb2 b
on a.职位代码=b.职位代码
select * ,是否进入第二轮考试=case when 名次<=计划数*3 then '1' else '' end
from t1,t2 where t1.职位代码=t2.职位代码
select a.*,[in]=(case when a.名次<=b.计划数*3 then '1' else '' end)
from tb1 a join tb2 b
on a.职位代码=b.职位代码
select a.*,[in]=(case when a.名次<=b.计划数*3 then '1' else '')
from tb1 a join tb2 b
on a.职位代码=b.职位代码