日期:2014-05-18 浏览次数:20660 次
--任意选一条 select * from tblStud a where fId=(select top 1 fId from tblStud where fName=a.fName order by newid()) --取最大或最小 select * from tblStud a where fId=(select min/*max*/(fId) from tblStud where fName=a.fName)
------解决方案--------------------
select fID, fName, fAge, fClass
from tblStud
where fID = (select top 1 fID
from tblStud
where fName = A.fName)
------解决方案--------------------
--按某一字段分组取最大(小)值所在行的数据
--2007-10-23于杭州
/*
数据如下:
name val memo
a 2 a2(a的第二个值)
a 1 a1--a的第一个值
a 3 a3:a的第三个值
b 1 b1--b的第一个值
b 3 b3:b的第三个值
b 2 b2b2b2b2
b 4 b4b4
b 5 b5b5b5b5b5
*/
--创建表并插入数据:
create table tb(name varchar(10),val int,memo varchar(20))
insert into tb values('a', 2, 'a2(a的第二个值)')