34,590
社区成员
发帖
与我相关
我的任务
分享
if OBJECT_ID('tb') is not null
drop table tb
go
create table tb
(
tm datetime,
bb int
)
go
insert into tb
select '2014-01-01 00:00:00',1
union all
select '2014-01-01 01:00:00',2
union all
select '2014-01-01 01:00:00',3
union all
select '2014-01-01 02:00:00',5
union all
select '2014-01-01 02:00:00',8
go
select * from tb a where not exists(select 1 from tb where tm=a.tm and bb>a.bb)
SELECT b.* FROM
(SELECT CONVERT(VARCHAR(10),tm,120) AS tm,MAX(bb) AS bb FROM tb GROUP BY CONVERT(VARCHAR(10),tm,120)) a LEFT JOIN tb b ON a.tm=CONVERT(VARCHAR(10),b.tm,120) AND a.bb=b.bb