select
max(t.a)
from
(select @v1 as a
union
select @v2
union
select @v3
union
select @v4) t
max(t.a)
from
(select @v1 as a
union
select @v2
union
select @v3
union
select @v4) t
解决方案 »
- 请问,在SQL Server 2008中哪里查看存储过程
- 一个SQL跨表查询的问题~~~
- SQLServer中,在一个已经有大量记录(如:1000W条)的表里添加一条记录,速度会不会慢于在一个空表里添加一条记录
- 为什么我的Oracle联不上啊?
- 【某书上的一句话】对于带有WHERE子句的SQL查询语句来说,使用COUNT(字段名)和COUNT(*)的效果是一样的。【是否错了呢?】
- sqlserver触发器往mysql插入数据错误问题
- SQL SERVER 2005 中,用存储过程分页,涉及到要通过外表查询获得的Count值进行排序
- 请问这句SQL SERVER7的SQL语句怎么写?
- SQL SERVER查询性能
- 这个SQL语句如何写,依据某个字段为条件,其他字段值显示问题?(SQL2000)
- 比较字符串是否相等的问题?
- 如何提高数据库的执行速度?
select @v1=1,@v2=3,@v3=9,@v4=2select id,a from
(
select @v1 a,id='v1'
union select @v2,id='v2'
union select @v3, id='v3'
union select @v4, id='v4') x
where a=
(select max(a) from
(
select @v1 a,id='v1'
union select @v2,id='v2'
union select @v3, id='v3'
union select @v4, id='v4') x)
/*
v3 9
*/
如果只取最大值不取名字
select max(a) from
(
select @v1 a,id='v1'
union select @v2,id='v2'
union select @v3, id='v3'
union select @v4, id='v4') x
create function dbo.f_max(@num1 decimal,@num2 decimal)
returns decimal
as
begin
return case when @num1<@num2 then @num2 else @num1 end
end
godeclare @v1 decimal
declare @v2 decimal
declare @v3 decimal
declare @v4 decimal
set @v1=89
set @v2=60
set @v3=109
set @v4=9
select dbo.f_max(@v1,dbo.f_max(@v2,dbo.f_max(@v3,@v4)))
go
drop function f_max