求sql:每一人多条记录,从中选择出时间字段中时间最早的一条
字段:
姓名,性别,培训时间
每人多条记录,多个“培训时间”,选择出“培训时间”最早的一条
[解决办法]
select 姓名,性别,min(培训时间) as 培训时间 from 表 group by 姓名,性别-- or --select 姓名,性别,min(培训时间) as 培训时间 from 表 group by 姓名,性别 order by 姓名-- or --select 姓名,性别,min(培训时间) as 培训时间 from 表 group by 姓名,性别 order by 3
[解决办法]
CREATE TABLE AAA (姓名 C(10),性别 C(2),培训时间 D)
INSERT INTO AAA VALUES ("ABC","男",{^1999.01.02})
INSERT INTO AAA VALUES ("ACD","男",{^2001.01.02})
INSERT INTO AAA VALUES ("ABF","男",{^1999.11.02})
INSERT INTO AAA VALUES ("ABC","男",{^2000.01.02})
INSERT INTO AAA VALUES ("ABF","男",{^1999.09.02})
INSERT INTO AAA VALUES ("ACD","男",{^1999.01.02})
SELECT 姓名,性别 ,MIN(培训时间) AS 培训时间 FROM AAA GROUP BY 姓名,性别