Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

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


Ïà¹ØÎÊ´ð£º

MSSQLÖÐÈçºÎÑ¡ÔñÒ»ÐÐÖÐ×îСµÄʱ¼ä£¿

Ò»ÕÅ±í£¬×ֶηÖΪ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 ......

¹ØÓÚMSSQLÔ¼ÊøÃû³ÆµÄÎÊÌâ - MS-SQL Server / »ù´¡Àà

×ֶεÄĬÈÏÖµÔ¼ÊøÉúËùµÄÔ¼ÊøÃû³Æϵͳ³£³£ÔÚºóÃæÌíÉÏÒ»¸öËæ»úµÄ×Ö·û´®£¬
Èç
DF__Admin__locked__014935CB
ÕâÑùÔì³ÉÒÔºóÔÚÐ޸ĸÄÔ¼ÊøµÄʱºòºÜÂé·³£¬ÔõôÉèÖò»ÈÃÊý¾Ý¿â×Ô¶¯Éú³ÉÕâÑùµÄËæ»úÃû³ÆµÄÔ¼ÊøÃû³Æ
¶øÏòÕâÑù ......

mssql£¬mysqlÓëmstlq

·´ÕýÎÒÊǾ­³£·Ö²»Çå¡­¡­
¼ÌÐøÉ¢·Ö
µÚÒ»¸ö±ÕÔ´£¬µÚ¶þ¸ö¿ªÔ´£¬µÚÈý¸öûŮÈËÔµ¡­¡­

LZÄ㻹ÓпÉÓ÷Öô£¿

ÒýÓÃ
LZÄ㻹ÓпÉÓ÷Öô£¿
5·Ö

ÒýÓÃ
µÚÒ»¸ö±ÕÔ´£¬µÚ¶þ¸ö¿ªÔ´£¬µÚÈý¸öûŮÈËÔµ¡­¡­

ÓÐÒâ˼¡£¿´±êÌ ......

mssql ʱ¼ä¶Ô±ÈÎÊÌâ ͬ±íͬ×ֶΠÊý¾ÝµÄʱ¼ä¶Ô±È

Çó ͬ±íͬ×ֶΠÊý¾ÝµÄʱ¼ä¶Ô±È Óï¾ä
È磺
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 ......

mssql Çó¶à×Ö¶Î×î´óÖµ2

×òÌì·¢µÄÕâ¸öÌû×Ó£º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 ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ