语句: select name from person where birthday = (select min(birthday) from person go
谢谢,还有个复杂点的情况,表中另有字段:level decimal not null, 如果要列出每个不同level中,年龄最小那些人的记录呢?
select name from person where birthday in (select max(birthday) from person goup by level) 不过 in 的效率好像不太高 你可以用临时表 select max(birthday) as birthday into #temp from person group by level select name from person inner join #temp on person.birthday=#temp.birthday drop table #temp
select * from person where birthday = (select distinct level,min(birthday) from person group by level)
to seafo: select max(birthday) as birthday into #temp from person group by level select name from person inner join #temp on person.birthday=#temp.birthday 第二句是不是应该再加一个连接?你看这样对吗? 如:select name from person,#temp where person.birthday=#temp.birthday and person.level=#temp.level
select *from where brithday in(select min(birthday) from person group by level )
level为sql server数据库关键字,将level改为aa : select name from person a, (select aa,min(birthday) as birthday from person group by aa) b where a.aa=b.aa and a.birthday=b.birthday
select name from person
where birthday = (select min(birthday) from person
go
如果要列出每个不同level中,年龄最小那些人的记录呢?
不过 in 的效率好像不太高
你可以用临时表
select max(birthday) as birthday into #temp from person group by level
select name from person inner join #temp on person.birthday=#temp.birthday
drop table #temp
where birthday = (select distinct level,min(birthday) from person group by level)
A: level = 1, birthday = 1979-01-01 00:00:00
B: level = 2, birthday = 1979-01-01 00:00:00
C: level = 2, birthday = 1980-01-01 00:00:00
结果应该是A、C,但是上面两位的结果大概会是A、B、C吧?
select max(birthday) as birthday into #temp from person group by level
select name from person inner join #temp on person.birthday=#temp.birthday
第二句是不是应该再加一个连接?你看这样对吗?
如:select name from person,#temp where person.birthday=#temp.birthday and
person.level=#temp.level
select name from person a,
(select aa,min(birthday) as birthday from person group by aa) b
where a.aa=b.aa and a.birthday=b.birthday