随便发个,看看有没有提高效率的可能~
A:
aabbcc
1001200709011.5
2001200709031.3
3001200709081.7
4002200709051.5
5002200709101.6
6003200709091.9
结果:取每个aa的BB最大的CC,显示出来
3001200709081.7
5002200709101.6
6003200709091.9
我写的是:
select a.aa,b.bb,a.cc from A a,(select aa,max(bb) as bb from A group by aa) b
where a.aa=b.aa and a.bb=b.bb
还有更好的写法吗?请大虾赐教!
[解决办法]
--try 1:
select * from A
where not exists(select 1 from A as B where aa=A.aa and bb> A.bb)
--try 2:
select * from A
where bb=(select max(bb) from A as B where aa=A.aa )
[解决办法]
--try 3:
select * from A
where bb=(select top 1 bb from A as B where aa=A.aa order by bb desc)
[解决办法]
如果你写的没有问题这个应该也是可行的
select aa,max(bb),stuff(max(bb+rtrim(cc)),1,8, ' ') as bb from A group by aa