例如表aa,有a,b,c,d 4个字段,要取每行中b,c,d 3个字段的最大值
A B C D
1 2 3 4
2 3 5 1
3 7 3 5
取出结果如下:
1 4
2 5
3 7
测试和实现如下:
create table aa
(
a int,
b int,
c int,
d int,
constraint pk_aa primary key( a )
)
insert into aa values(1,2,3,4);
insert into aa values(2,3,5,1);
insert into aa values(3,7,3,5);
commit;
select * from aa;
select aa.a, max(tmp.bb)
from aa,
(select a, b as bb
from aa
union all
select a, c as bb
from aa
union all
select a, d as bb from aa) tmp
where aa.a = tmp.a
group by aa.a
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/70612/viewspace-1029046/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/70612/viewspace-1029046/