declare @a int
declare @b int
declare @c int
declare @d int
set @a=1
set @b=2
set @c=3
set @d=4
select max(t.A) from ( select @a as A union all select @b as A union all select @c as A union all select @d ) t
本文通过一个具体的SQL示例介绍了如何使用变量并结合子查询来找出最大值。示例中定义了四个整型变量并利用这些变量构建了一个临时表,最后通过MAX函数返回了这些变量中的最大值。
declare @a int
declare @b int
declare @c int
declare @d int
set @a=1
set @b=2
set @c=3
set @d=4
select max(t.A) from ( select @a as A union all select @b as A union all select @c as A union all select @d ) t

被折叠的 条评论
为什么被折叠?