数据筛选(对不住了,只有25分了)
表:
a b c
-----------
a 1 p1
a 2 vvv
a 3 tttttttttt
t 1 p
t 2 tttttttttt
r 1 ppp
r 2 st
r 3 tttttttttt
要求:
以a列分组,选取b列为最大值的c列值,得到结果如下:
a c
------
a tttttttttt
t tttttttttt
r tttttttttt
请用一条语句达到以上结果值?
[解决办法]
SELECT * FROM TB T WHERE B=(SELECT MAX(B) FROM TB WHERE A=T.A)
[解决办法]
select A,(select C from tb where A=x.a and B=MAX(x.b)) as C
from TB as x
group by A
[解决办法]
select a,c
from tb t
where not exists(select 1 from tb where a=t.a and b>t.b)