[ת] mysql·Ö×éȡÿ×éÇ°¼¸Ìõ¼Ç¼(ÅÅÃû)
--°´Ä³Ò»×ֶηÖ×éÈ¡×î´ó(С)ÖµËùÔÚÐеÄÊý¾Ý
/* Êý¾ÝÈçÏ£º 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µÄµÚ¶þ¸öÖµ)')insert into tb values('a', 1, 'a1--aµÄµÚÒ»¸öÖµ')insert into tb values('a', 3, 'a3:aµÄµÚÈý¸öÖµ')insert into tb values('b', 1, 'b1--bµÄµÚÒ»¸öÖµ')insert into tb values('b', 3, 'b3:bµÄµÚÈý¸öÖµ')insert into tb values('b', 2, 'b2b2b2b2')insert into tb values('b', 4, 'b4b4')insert into tb values('b', 5, 'b5b5b5b5b5')go
--Ò»¡¢°´name·Ö×éÈ¡val×î´óµÄÖµËùÔÚÐеÄÊý¾Ý¡£
--·½·¨1£º select a.* from tb a where val = (select max(val) from tb where name = a.name) order by a.name--·½·¨2£º select a.* from tb a where not exists(select 1 from tb where name = a.name and val > a.val)--·½·¨3£º select a.* from tb a,(select name,max(val) val from tb group by name) b where a.name = b.name and a.val = b.val order by a.name--·½·¨4£º select a.* from tb a inner join (select name , max(val) val from tb group by name) b on a.name = b.name and a.val = b.val order by a.name--·½·¨5 select a.* from tb a where 1 > (select count(*) from tb where name = a.name and val > a.val ) order by a.name/* name val memo ---------- ----------- -------------------- a 3 a3:aµÄµÚÈý¸öÖµ b 5 b5b5b5b5b5*/
--¶þ¡¢°´name·Ö×éÈ¡val×îСµÄÖµËùÔÚÐеÄÊý¾Ý¡£
--·½·¨1£º select a.* from tb a where val = (select min(val) from tb where name = a.name) order by a.name--·½·¨2£º select a.* from tb a where not exists(select 1 from tb where name = a.name and val < a.val)--·½·¨3£º select a.* from tb a,(select name,min(val) val from tb group by name) b where a.name = b.name and a.val = b.val order by a.name--·½·¨4£º select a.* from tb a inner join (select name , min(val) val from tb group by name) b on a.name = b.name and a.val = b.val order by a.name--·½·¨5 select a.* from tb a where 1 > (select count(*) from tb where name = a.name and val < a.val) order by a.name/* name val memo ---------- ----------- -------------------- a 1 a1--aµÄµÚÒ»¸öÖµ b 1 b1--bµÄµÚÒ»¸öÖµ*/
--Èý¡¢°´name·Ö×éÈ¡µÚÒ»´Î³öÏÖµÄÐÐËùÔÚµÄÊý¾Ý¡£
select a.* from tb a where val = (select top 1 val from tb where name = a.name) order by a.name/* name val memo ---------- ----------- -------------------- a 2 a2(aµÄµÚ¶þ¸öÖµ) b 1 b1--bµÄµÚÒ»¸öÖµ*/
--ËÄ¡¢°´name·Ö×éËæ»úÈ¡Ò»ÌõÊý¾Ý¡£
select a.* from tb a where val = (select top 1 val from tb where name = a.name order by newid()) order by a.name/* name val memo ---------- ----------- -------------------- a 1 a1--aµÄµÚÒ»¸öÖµ b 5 b5b5b5b5b5*/
--Îå¡¢°´name·Ö×éÈ¡×îСµÄÁ½¸ö(N¸ö)val
select a.* from tb a where 2 > (select count(*) from tb where name = a.name and val < a.val ) order by a.name,a.valselect a.* from tb a where val in (select top 2 val from tb where name=a.name order by val) order by a.name,a.valselect a.* from tb a where exists (select count(*) from tb where name = a.name and val < a.val having Count(*) < 2) order by a.name/* name val memo ---------- ----------- -------------------- a 1 a1--aµÄµÚÒ»¸öÖµ a 2 a2(aµÄµÚ¶þ¸öÖµ) b 1 b1--bµÄµÚÒ»¸öÖµ b 2 b2b2b2b2*/
--Áù¡¢°´name·Ö×éÈ¡×î´óµÄÁ½¸ö(N¸ö)val
select a.* from tb a where 2 > (select count(*) from tb where name = a.name and val > a.val ) order by a.name,a.valselect a.* from tb a where val in (select top 2 val from tb where name=a.name order by val desc) order by a.name,a.valselect a.* from tb a where exists (select count(*) from tb where name = a.name and val > a.val having Count(*) < 2) order by a.name/* name val memo ---------- ----------- -------------------- a 2 a2(aµÄµÚ¶þ¸öÖµ) a 3 a3:aµÄµÚÈý¸öÖµ b 4 b4b4 b 5 b5b5b5b5b5*/
--Æߣ¬¼ÙÈçÕûÐÐÊý¾ÝÓÐÖظ´£¬ËùÓеÄÁж¼Ïàͬ¡£
/* Êý¾ÝÈçÏ£º name val memo a 2 a2(aµÄµÚ¶þ¸öÖµ) a 1 a1--aµÄµÚÒ»¸öÖµ a 1 a1--aµÄµÚÒ»¸öÖµ a 3 a3:aµÄµÚÈý¸öÖµ a 3 a3:aµÄµÚÈý¸öÖµ b 1 b1--bµÄµÚÒ»¸öÖµ b 3 b3:bµÄµÚÈý¸öÖµ b 2 b2b2b2b2 b 4 b4b4 b 5 b5b5b5b5b5*/
--ÔÚsql server 2000ÖÐÖ»ÄÜÓÃÒ»¸öÁÙʱ±íÀ´½â¾ö£¬Éú³ÉÒ»¸ö×ÔÔöÁУ¬ÏȶÔvalÈ¡×î´ó»ò×îС£¬È»ºóÔÙͨ¹ý×ÔÔöÁÐÀ´È¡Êý¾Ý¡£
--´´½¨±í²¢²åÈëÊý¾Ý£º
create table tb(name varchar(10),val int,memo varchar(20))insert into tb values('a', 2, 'a2(aµÄµÚ¶þ¸öÖµ)')insert into tb values('a', 1, 'a1--aµÄµÚÒ»¸öÖµ')insert into tb values('a', 1, 'a1--aµÄµÚÒ»¸öÖµ')insert into tb values('a', 3, 'a3:aµÄµÚÈý¸öÖµ')insert into tb values('a', 3, 'a3:aµÄµÚÈý¸öÖµ')insert into tb values('b', 1, 'b1--bµÄµÚÒ»¸öÖµ')insert into tb values('b', 3, 'b3:bµÄµÚÈý¸öÖµ')insert into tb values('b', 2, 'b2b2b2b2')insert into tb values('b', 4, 'b4b4')insert into tb values('b', 5, 'b5b5b5b5b5')go select * , px = identity(int,1,1) into tmp from tbselect m.name,m.val,m.memo from (select t.* from tmp t where val = (select min(val) from tmp where name = t.name) ) m where px = (select min(px) from (select t.* from tmp t where val = (select min(val) from tmp where name = t.name) ) n where n.name = m.name)drop table tb,tmp/* name val memo ---------- ----------- -------------------- a 1 a1--aµÄµÚÒ»¸öÖµ b 1 b1--bµÄµÚÒ»¸öÖµ (2 ÐÐÊÜÓ°Ïì)*/
--ÔÚsql server 2005ÖпÉÒÔʹÓÃrow_numberº¯Êý£¬²»ÐèҪʹÓÃÁÙʱ±í¡£
--´´½¨±í²¢²åÈëÊý¾Ý£º
create table tb(name varchar(10),val int,memo varchar(20))insert into tb values('a', 2, 'a2(aµÄµÚ¶þ¸öÖµ)')insert into tb values('a', 1, 'a1--aµÄµÚÒ»¸öÖµ')insert into tb values('a', 1, 'a1--aµÄµÚÒ»¸öÖµ')insert into tb values('a', 3, 'a3:aµÄµÚÈý¸öÖµ')insert into tb values('a', 3, 'a3:aµÄµÚÈý¸öÖµ')insert into tb values('b', 1, 'b1--bµÄµÚÒ»¸öÖµ')insert into tb values('b', 3, 'b3:bµÄµÚÈý¸öÖµ')insert into tb values('b', 2, 'b2b2b2b2')insert into tb values('b', 4, 'b4b4')insert into tb values('b', 5, 'b5b5b5b5b5')go select m.name,m.val,m.memo from (select * , px = row_number() over(order by name , val) from tb ) m where px = (select min(px) from (select * , px = row_number() over(order by name , val) from tb ) n where n.name = m.name)drop table tb/* name val memo ---------- ----------- -------------------- a 1 a1--aµÄµÚÒ»¸öÖµ b 1 b1--bµÄµÚÒ»¸öÖµ (2 ÐÐÊÜÓ°Ïì)*/
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ