sql代码收集

主要是记录些平时看到的,自己想到的比较好的sql

1.求每行最大值

 

create   table   T(A   decimal(10,1),   B   decimal(10,1),   C   decimal(10,1),   D   decimal(10,1),   E   decimal(10,1))
insert   T   select   -21.5, -15.0, -5.0,   null,   null
union   all   select   -5.5, -11.5, null,   null,   null
union   all   select   -1.0, -16.5, -10.5,   null,   null

select   *,
max_value=(
select   max(A)   from
(  
select   A  
union   all  
select   B
union   all  
select   C
union   all  
select   D
union   all  
select   E
)t)
from   T

drop table T

posted @ 2008-09-26 12:39  hyqwan  阅读(360)  评论(7)    收藏  举报