mssql Çó¶à×Ö¶Î×î´óÖµ
//Ïà¹Ø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
Ïà¹ØÎÊ´ð£º
Ò»ÕÅ±í£¬×ֶηÖΪid,time1,time2,time3,time4,time5
ÇëÎÊÎÒÓ¦¸ÃÈçºÎÑ¡ÔñIDΪ1µÄÄÇÌõ¼Ç¼ÖÐtimeʱ¼ä×îСµÄÖµÄØ£¿
UP!
[code=SQL][/code]select min(t) from
(select time1 as t from t1 where id ......
×ֶεÄĬÈÏÖµÔ¼ÊøÉúËùµÄÔ¼ÊøÃû³Æϵͳ³£³£ÔÚºóÃæÌíÉÏÒ»¸öËæ»úµÄ×Ö·û´®£¬
Èç
DF__Admin__locked__014935CB
ÕâÑùÔì³ÉÒÔºóÔÚÐ޸ĸÄÔ¼ÊøµÄʱºòºÜÂé·³£¬ÔõôÉèÖò»ÈÃÊý¾Ý¿â×Ô¶¯Éú³ÉÕâÑùµÄËæ»úÃû³ÆµÄÔ¼ÊøÃû³Æ
¶øÏòÕâÑù ......
·´ÕýÎÒÊǾ³£·Ö²»Çå¡¡
¼ÌÐøÉ¢·Ö
µÚÒ»¸ö±ÕÔ´£¬µÚ¶þ¸ö¿ªÔ´£¬µÚÈý¸öûŮÈËÔµ¡¡
LZÄ㻹ÓпÉÓ÷Öô£¿
ÒýÓÃ
LZÄ㻹ÓпÉÓ÷Öô£¿
5·Ö
ÒýÓÃ
µÚÒ»¸ö±ÕÔ´£¬µÚ¶þ¸ö¿ªÔ´£¬µÚÈý¸öûŮÈËÔµ¡¡
ÓÐÒâ˼¡£¿´±êÌ ......
Çó ͬ±íͬ×ֶΠÊý¾ÝµÄʱ¼ä¶Ô±È Óï¾ä
È磺
ID DATE_TIME
1 2010Äê3ÔÂ31ÈÕ 15:14:46
2 2010Äê3ÔÂ31ÈÕ 15:20:54
3 2010Äê3ÔÂ31ÈÕ 15:23:01
4 2010Äê3ÔÂ31ÈÕ 15:25:06
5 2010Äê3ÔÂ31ÈÕ 15 ......
×òÌì·¢µÄÕâ¸öÌû×Ó£ºhttp://topic.csdn.net/u/20100407/15/1af60691-1b11-4a0a-bf85-6187add9fb4f.html
SQL code:
select tId,max(class1) maxClass
from(select tId,class1 from tb1 union all select tId,cla ......