22,298
社区成员
发帖
与我相关
我的任务
分享select persID,min([time])as time
from tb
group by persID order by time ascSELECT * FROM TB T WHERE NOT EXISTS(SELECT 1 FROM TB WHERE PersID=T.PersID AND TIME<T.TIME) ORDER BY TIME-- =========================================
-- -----------t_mac 小编-------------
---希望有天成为大虾----
-- =========================================
IF OBJECT_ID('tb') IS NOT NULL
DROP TABLE tb
GO
CREATE TABLE tb(persID int ,[time] varchar(10))
go
insert into tb
select
1 , '05:00' union all select
1 , '06:00' union all select
1 , '08:00' union all select
2 , '09:00' union all select
2 , '10:00' union all select
3 , '07:00'
go
select persid,min(time)as time
from tb
group by persid
order by time
/*------------
persID time
----------- ----------
persid time
----------- ----------
1 05:00
3 07:00
2 09:00
-------*/