姓名,性别,培训时间
每人多条记录,多个“培训时间”,选择出“培训时间”最早的一条
6 个解决方案
#1
select 姓名,性别,max(培训时间) as 培训时间 from 表 order by 培训时间 group by 培训时间
#2
select 姓名,性别,min(培训时间) as 培训时间 from 表 group by 姓名,性别
#3
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
#4
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 姓名,性别
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 姓名,性别
#5
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 * FROM aaa a WHERE NOT exists(SELECT 1 FROM aaa WHERE a.姓名=姓名 AND a.培训时间<培训时间)
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 * FROM aaa a WHERE NOT exists(SELECT 1 FROM aaa WHERE a.姓名=姓名 AND a.培训时间<培训时间)
#6
谢谢以上各位
#1
select 姓名,性别,max(培训时间) as 培训时间 from 表 order by 培训时间 group by 培训时间
#2
select 姓名,性别,min(培训时间) as 培训时间 from 表 group by 姓名,性别
#3
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
#4
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 姓名,性别
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 姓名,性别
#5
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 * FROM aaa a WHERE NOT exists(SELECT 1 FROM aaa WHERE a.姓名=姓名 AND a.培训时间<培训时间)
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 * FROM aaa a WHERE NOT exists(SELECT 1 FROM aaa WHERE a.姓名=姓名 AND a.培训时间<培训时间)
#6
谢谢以上各位