a b c d e f g h i j
28 89 56 43 58 32 62 65 21 32
101 72 90 21 32 4 12 34 11 201假如说现在有a到j这么多列 查询出这张表的这么多列的一个最大值
只想到了用union相关联查,看看大家有没有什么好的办法,效率高一些的
解决方案 »
- 求助:调用带参数的存储过程
- pl/sql查询时同时出现一个字段,但是该字段满足不同的条件。
- 怎么我的sql 2000安装了 sp4补丁,版本号却是 8.00.260(好象,反正不是760以上)?
- 一台服务器两套数据库 SQLSERVER2000急急!!!!!!系统用的是win2003
- 部分客户端连接不到SQL server 2000
- SQL SERVER 2005右键无单步调试菜单?
- 如何写一个存储过程向数据库表保存jpg图片。
- 如何查询一段序列数字中缺少的数字的语句
- 各位GG,JJ,DD,MM,你们准备如何虚度五一大好时光呀?
- 从一个项目的多条记录中选择时间最近的一条。
- Sql 语句,获取当月天数,以及本年天数
- convert日期格式dd mon yy
select max(col) from
(select max(a) col from tb
union
select max(b) from tb union
select max(c) from tb union
select max(d) from tb union
...) t
我局的用这个union 效率不高吧 数量大了反应行吗
create table TryTable
(a int,b int, c int,d int,e int,f int,g int,h int,i int,j int)
insert TryTable
select 28 ,89 ,56 ,43 ,58 ,32 ,62 ,65 ,21 , 32 union all
select 101 ,72 ,90 ,21 ,32 ,4 ,12 ,34 ,11 , 201select max(maxvaluse) as maxvaluse from TryTable
unPivot(maxvaluse for [type] in(a,b,c,d,e,f,g,h,i,j)) as a--maxvaluse
-------------
--201
--create table #a(id int,a int, b int, c int, d int, e int, f int, g int, h int, i int, j int )
--insert into #a values(1,28, 89 , 56 , 43 , 58 ,32 , 62 , 65 , 21 , 32)
--insert into #a values(1,101 ,72 , 90 , 21 , 32 , 4 , 12 , 34 , 11 , 201)select * from #adeclare @a int
declare @b int
select @a=102
select @b=1
while @b<>0
begin
select
@b=SUM(a)+SUM(b)+SUM(a)+SUM(b)+SUM(b)+SUM(e)+SUM(f)+SUM(g)+SUM(h)+SUM(i)+SUM(j)
from
(
select ID,
case when a-@a<0 then 0 else a-@a end a,
case when b-@a<0 then 0 else b-@a end b,
case when c-@a<0 then 0 else c-@a end c,
case when d-@a<0 then 0 else d-@a end d,
case when e-@a<0 then 0 else e-@a end e,
case when f-@a<0 then 0 else f-@a end f,
case when g-@a<0 then 0 else g-@a end g,
case when h-@a<0 then 0 else h-@a end h,
case when i-@a<0 then 0 else i-@a end i,
case when j-@a<0 then 0 else j-@a end j
from #a
) tt
group by id
select @a=@a+1
end
select @a-1 as maxnum
2 FROM
3 (SELECT ID
4 FROM T
5 ORDER BY ID DESC NULLS LAST)
6 WHERE ROWNUM = 1;ID