读书人

急求一sql句子!解决办法

发布时间: 2012-03-01 10:25:46 作者: rapoo

急求一sql句子!
例如表aa:
aa bb cc
1 255 20061212
1 15 20061210
2 33 20060612
2 11 20060101
按cc用DESC排序了,
如我想删除where aa= '2 'or 其他中处的最近时间资料.
结果表aa:
aa bb cc
1 255 20061212
2 33 20060612

谢谢!


[解决办法]
create table tt
(
aa int ,
bb int ,
cc varchar(08)
)
insert into tt
select 1, 255 , '20061212 ' union
select 1, 15 , '20061210 ' union
select 2, 33 , '20060612 ' union
select 2, 11 , '20060101 '

select a.*
from tt a
where not exists
(select 1 from tt where aa = a.aa and cc > a.cc)
[解决办法]
delete from t where aa=2 and cc in (select max (cc) from t where aa =2)
select * from t
[解决办法]
http://community.csdn.net/Expert/topic/5275/5275251.xml?temp=.1500818

帮我看看哈.

读书人网 >SQL Server

热点推荐