如题,怎么让结果MaxValue显示为最大的那个数“7”?
--建表
declare @t table(
a int,
b int,
c int,
d int,
e int,
f int
)
--插数据
insert into @t select 5,6,4,1,7,5--显示最大值。这行如何实现?
select max(a,b,c,d,e,f) as MaxValue, * from @t
--建表
declare @t table(
a int,
b int,
c int,
d int,
e int,
f int
)
--插数据
insert into @t select 5,6,4,1,7,5--显示最大值。这行如何实现?
select max(a,b,c,d,e,f) as MaxValue, * from @t
select (case when (a >= b) then a when (b >= c) then c else d end) from @t
declare @t table(id int, a int, b int, c int, d int, e int, f int)insert into @t select 1, 5,6,4,1,7,5 --7
insert into @t select 2, 1,6,4,1,7,8 --8
insert into @t select 3, 8,6,4,1,7,1 --8
insert into @t select 4, 5,6,8,1,7,5 --8
insert into @t select 5, 5,5,5,5,5,5 --5select * from @tselect a.id,
(select max(a) from (
select a from @t where id=a.id
union all select b from @t where id=a.id
union all select c from @t where id=a.id
union all select d from @t where id=a.id
union all select e from @t where id=a.id
union all select f from @t where id=a.id
) bbb)
from @t a
declare @t table(id int, a int, b int, c int, d int, e int, f int)insert into @t select 1, 5,6,4,1,7,5 --7
insert into @t select 2, 1,6,4,1,7,8 --8
insert into @t select 3, 8,6,4,1,7,1 --8
insert into @t select 4, 5,6,8,1,7,5 --8
insert into @t select 5, 5,5,5,5,5,5 --5select * from @tselect a.id,
(select max(a) from (
select a --from @t where id=a.id
union all select b --from @t where id=a.id
union all select c --from @t where id=a.id
union all select d --from @t where id=a.id
union all select e --from @t where id=a.id
union all select f --from @t where id=a.id
) bbb)
from @t a
when b > a and b > c and b > d and b > e and b > f then b
...
end
from @t