select min(tid) --取ID號就小那個 from #t group by 学号 --分組
if object_id('成绩单') is not null drop table 成绩单 go create table 成绩单 (学号 varchar(4), 姓名 nvarchar(4), 学科 varchar(4), 成绩 real) insert 成绩单 select '01', 'LI', '语文', 80 union all select '01', 'LI', '数学', 90 union all select '12', 'WU', '数学', 85 union all select '22', '王东', '英语', 77 union all select '22', '王东', '历史', 88select * , tid=identity(int) into #t from 成绩单 ----------测试语句 --------------------------- 想问问-- select min(tid) -- from #t -- group by 学号select * from #tselect * from #t where tid in (select min(tid) from #t group by 学号)drop table #t--比较一下两个结果,对select min(tid) from #t group by 学号应该就可以理解了吧
from #t
group by 学号 --分組
go
create table 成绩单 (学号 varchar(4), 姓名 nvarchar(4),
学科 varchar(4), 成绩 real)
insert 成绩单 select '01', 'LI', '语文', 80
union all select '01', 'LI', '数学', 90
union all select '12', 'WU', '数学', 85
union all select '22', '王东', '英语', 77
union all select '22', '王东', '历史', 88select * , tid=identity(int)
into #t
from 成绩单 ----------测试语句
---------------------------
想问问-- select min(tid)
-- from #t
-- group by 学号select * from #tselect * from #t
where tid in (select min(tid)
from #t
group by 学号)drop table #t--比较一下两个结果,对select min(tid)
from #t
group by 学号应该就可以理解了吧