create table test(序号 int,姓名 varchar(20),费用 decimal(5,1)) insert test select 1,'小张',1.2 union all select 2,'小李',1.3 union all select 3,'小王',1.4 union all select 4,'小邓',1.5select distinct case when (select 费用 from test where 姓名='小李')-(select 费用 from test where 姓名='小王')>0 then '大于小王' when (select 费用 from test where 姓名='小李')-(select 费用 from test where 姓名='小王')<0 then '小于小王' when (select 费用 from test where 姓名='小李')-(select 费用 from test where 姓名='小王')=0 then '等于小王' end from testdrop table test
trySelect * From TableName A Where Exists(Select 姓名 From TableName Where 姓名 = N'小李' And 费用 < A.费用) And 姓名 = N'小王'
select * from #test a where exists(select 1 from #test where a.费用>费用 and a.姓名='小王' and 姓名='小李') --这个是大于小李最少的
select * from tablename where 费用 >(select 费用 from tablename where name = '小李') order by id dsec
声明一个变量 declare @bool int --如果大于,则置1,否则置0 --读取数据库中的小李的费用 declare @costl float select @costl = 费用 from biao where 姓名 = '小李' declare @costw float select @costw = 费用 from biao where 姓名 = '小王' if @costl >@costw set @bool = 1 else set @bool = 0 这有一定的问题,在计算机中两个浮点数比较大小是不合适的!呵呵..不过可以参考一下
insert test select 1,'小张',1.2
union all select 2,'小李',1.3
union all select 3,'小王',1.4
union all select 4,'小邓',1.5select distinct case when (select 费用 from test where 姓名='小李')-(select 费用 from test where 姓名='小王')>0 then
'大于小王'
when (select 费用 from test where 姓名='小李')-(select 费用 from test where 姓名='小王')<0 then
'小于小王'
when (select 费用 from test where 姓名='小李')-(select 费用 from test where 姓名='小王')=0 then
'等于小王' end
from testdrop table test
Where Exists(Select 姓名 From TableName Where 姓名 = N'小李' And 费用 < A.费用)
And 姓名 = N'小王'
--这个是大于小李最少的
select * from tablename where 费用 >(select 费用 from tablename where name = '小李') order by id dsec
declare @bool int --如果大于,则置1,否则置0
--读取数据库中的小李的费用
declare @costl float
select @costl = 费用 from biao where 姓名 = '小李'
declare @costw float
select @costw = 费用 from biao where 姓名 = '小王'
if @costl >@costw
set @bool = 1
else
set @bool = 0
这有一定的问题,在计算机中两个浮点数比较大小是不合适的!呵呵..不过可以参考一下