- 论坛徽章:
- 0
|
table A ( cola1, cola2, cola3,cola4,.......);
unique index on A(cola1,cola2,cola3);
现在要选出cola1, cola2, cola3,cola4插入临时表,并保证
1、cola1唯一
2、在A中cola1对应cola2为最大
3、在A中cola1,max(cola2)共同对应cola3最大
我是这么写的
select cola1,max(cola2) cola2
from A
group by cola1 into temp tmp1;
select tmp1.cola1,tmp1.cola2,max(A.cola3) cola3
from tmp1,A
where tmp1.cola1=A.cola1 and tmp1.cola2=A.cola2 into temp tmp2;
select tmp2.cola1,tmp2.cola2,tmp2.cola3,A.cola4
from tmp2,A
where tmp2.cola1=A.cola1 and tmp2.cola2=A.cola2
and tmp2.cola3=A.cola3
现在要在一句SQL中完成。 |
|