//Ïà¹Øsql
SQL code:
create table tb1
(
tId int,
tName nvarchar(20),
class1 int,
class2 int
)
insert into tb1
select 1,'test',10,20
union all
select 1,'test1',20,35
union all
select 1,'test2',30,30
union all
select 2,'test21',30,85
union all
select 2,'test22',50,75
union all
select 3,'test31',60,65
union all
select 3,'test32',70,70
//µ¥¸ö×ֶεĻᣬÏÂÃæÊÇÇ󵥸ö×ֶεÄ
SQL code:
select a.* from tb1 a,(select tId,max(class1) as maxT from tb1 group by tId) b
where a.tId=b.tId and a.class1=b.maxT order by a.tId
//Êý¾ÝÏÔʾÈçÏÂ
SQL code:
tId tName class1 class2
1 test2 30 30
2 test22 50 75
3 test32 70 70
//ÎÒÏëÏÔʾΪ
SQL code:
tId tName maxClass
1 test2 35
2 test22 85
3 test32 70
ÎÒÏëÒªµÄ½á¹û¾ÍÊÇclass1,class2²»Çø·Ö£¬È¡×î´óÖµ¡£
//лл¡£
SELECT TID,TNAME,MAX(CLASS1 )
from (
SELECT TID,TNAME,CLASS1 from TB
UNION