日期:2014-05-19  浏览次数:20451 次

关于条件语句
请教下大家:一个表中有4列:xh,a,b,c,现在要根据这个表查询xh的完成情况:如果c> a,则xh已完成,否则如果b+c> =a,则xh生产中,否则xh未生产,该怎么查询生成一个表xh,wc(完成情况)?

------解决方案--------------------
create table #t(xh varchar(100), a int, b int, c int)
insert into #t
select '001 ', 3, 0, 4 union all
select '002 ' , 4 , 1 , 1 union all
select '003 ' , 4 , 2 , 3


select
xh,
case when c> a then '已完成 ' when b+c> =a then '生产中 ' else '未生产 ' end as wc
from #t


drop table #t