第1个回答 2011-11-16
这个不是一个单纯的SQL就可以完成的,需要使用游标,或者存储过程。
select max(A) from table_name; ----取A列最大的记录,譬如说=100;
select count(A) as countA from table_name where A=100;----取等于最大值的有多少条数据;
然后做判断
if countA =1
------按照你的具体做法实现SQL
else
select max(B) from table_name;
fi本回答被网友采纳
第2个回答 2011-11-16
select max(A), B
from (select A, B, row_number() over(partition by A order B DESC) rk from tab) t
where rk = 1
group by B
第3个回答 2017-12-16
select t3.*
from t t3,
(
select a,max(b) b from t t22,
(
select max(a) a
from t t11
) t1 where t1.a = t22.a
group by t22.a
) t2
where t3.a = t2.a and t2.b = t2.b