MySQL µÄǶÌײéѯ
×î½üÔÚMySQLÉÏ×öÁ˵㹤×÷£¬·¢ÏֺܶàÈ˶¼ÔÚѯÎÊMySQLǶÌײéѯµÄÎÊÌ⣬Ðí¶àÈ˶¼¾õµÃMySQL²»Ö§³ÖǶÌײéѯ£¬ÆäʵMySQl´Ó4.11°æºóÒѾÍêȫ֧³ÖǶÌײéѯÁË£¬ÄÇôÏÂÃæÎÒ¾ÙЩ¼òµ¥µÄǶÌײéѯµÄÀý×Ó°É£¨Ô´³ÌÐòÀ´×ÔMySQL User Manual£©£º
1. SELECTÓï¾äµÄ×Ó²éѯ:
Óï·¨: SELECT ... from (subquery) AS name ...
ÏÈ´´½¨Ò»¸ö±í:
CREATE TABLE t1 (s1 INT, s2 CHAR(5), s3 FLOAT);
INSERT INTO t1 VALUES (1,'1',1.0);
INSERT INTO t1 VALUES (2,'2',2.0);
ÎÒÃǾͿÉÒÔ½øÐÐÒÔϵÄǶÌײéѯÁË:
SELECT sb1,sb2,sb3
from (SELECT s1 AS sb1, s2 AS sb2, s3*2 AS sb3 from t1) AS sb
WHERE sb1 > 1;
½á¹ûÊÇ£º 2, '2', 4.0.
ÎÒÃÇÖªµÀÏÂÃæÓï¾äÊDz»»áµÃµ½ÕýÈ·½á¹ûµÄ£¬ÒòΪ¶Ô¾¹ýGroup byÅÅÐòµÄ¼¯ºÏ½øÐÐÇó¾ùÖµÊDz»Äܵõ½ÕýÈ·´ð°¸µÄ£º
SELECT AVG(SUM(column1)) from t1 GROUP BY column1
ËùÒÔÎÒÃÇ¿ÉÒÔͨ¹ýÏÂÃæµÄǶÌײéѯʵÏÖͬÑùµÄЧ¹û£º
SELECT AVG(sum_column1)
from (SELECT SUM(column1) AS sum_column1
from t1 GROUP BY column1) AS t1;
2.ÐеÄ×Ó²éѯ£¨Row Subquery£©£º
¿´ÏÂÃæµÄÀý×Ó£º
SELECT * from t1 WHERE ROW(1,2) = (SELECT column1, column2 from t2);
Õâ¸ö²éѯÊÇ·µ»Øcolumn1µÈÓÚcolumn2µÄ½á¹ûÐС£Rowº¯ÊýÖеÄ1ºÍ2Ï൱ÓÚ¹¹Ôì²ÎÊý¡£Ïë±ØBlogjavaÉϵÄͬ־¶ÔÕâЩӦ¸Ã±È½ÏÇå³þ£¬Ò²²»È¥Ïêϸ½éÉÜÁË¡£
3.ʹÓÃExistºÍNot Exist²ÎÊý
ÕâÀïµÄExistºÍNot ExistÓÃ;¼°Ó÷¨ºÍÔÚÆäËûûÓÐʲô´óµÄÇø±ð,ÎҾͼòµ¥¾Ù¼¸¸ö·¶ÀýºÃÁË:
·¶ÀýÒ»: SELECT DISTINCT store_type from Stores
WHERE EXISTS (SELECT * from Cities_Stores
WHERE Cities_Stores.store_type = Stores.store_type);
·¶Àý¶þ: SELECT DISTINCT store_type from Stores
WHERE NOT EXISTS (SELECT * from Cities_Stores
WHERE Cities_Stores.store_type = Stores.store_type);
·¶ÀýÈý: Õâ¸öÀý×ÓÖÐǶÌ×ʹÓÃÁËNot ExistÓï·¨£¬ÉÔ΢עÒâһϣº
SELECT DISTINCT store_type from Stores S1
WHERE NOT EXISTS (
SELECT * from Cities WHERE NOT EXISTS (
SELECT * from Cities_Stores
Ïà¹ØÎĵµ£º
Ò»°ã¸³Ó踡µãÁеÄÖµ±»ËÄÉáÎåÈëµ½Õâ¸öÁÐËùÖ¸¶¨µÄÊ®½øÖÆÊý¡£Èç¹ûÔÚÒ»¸öFLOAT(8, 1)µÄÁÐÖд洢1. 2 3 4 5 6£¬Ôò½á¹ûΪ1. 2¡£Èç¹û½«ÏàͬµÄÖµ´æÈëFLOAT(8, 4) µÄÁÐÖУ¬Ôò½á¹ûΪ1. 2 3 4 6¡£Õâ±íʾӦ¸Ã¶¨Òå¾ßÓÐ×㹻λÊýµÄ¸¡µãÁÐÒÔ±ãµÃµ½¾¡¿ÉÄܾ«È·µÄÖµ¡£Èç¹ûÏ뾫ȷµ½Ç§·ÖÖ®Ò»£¬ÄǾͲ»Òª¶¨Òåʹ¸ÃÀà ......
С½á£º
Ê×ÏÈÒªÕÒµ½mySqlµÄÅäÖÃÎļþ
my.cnf
È»ºóÒª¸Ä¶ÔµØ·½
[client]ºÍ[mysqld]ÏÂͬʱ¼ÓÉÏdefault-character-set=utf8
È»ºó¼ÇµÃÐèÒªÖØÆôMySql.ÇÒ±£Ö¤¿Í»§¶ËµÄÁ¬½Ó·½Ê½Ò²ÊÇutf8.
Ԥף×Ô¼ºÐµÄÒ»Ä꣬¼ªÏéÈçÒ⣬ÐÄÏëʳɣ¡ ......
/*****************by
garcon1986************************************************************/
ͨÓùæÔò£º
Õû
¸öÊý¾Ý¿âÀïµÄÃû×Ö¶¼¾¡Á¿Ê¹ÓÃСд¡£ÕâÑùÄÜÏû³ýÓÉÓÚ´óСд£¨
case-sensitivity
£©´øÀ´
µÄ´íÎó¡£
Mysql
ĬÈÏÇø·Ö´óСд¡£
ʹ
ÓÃÏ»®Ïß¶Ï¿ªÃû×Ö£¬Ãû×ÖÖв»ÄÜ
ʹÓÿոñ¡£
Ãû×ÖÖо¡Á¿²»Òª
ʹ
ÓÃÊý ......
mysqlË÷ÒýÏê½â,Õª×Ô¡¶MySQL 5ȨÍþÖ¸ÄÏ¡·
±¾ÎĽéÉÜÁËÊý¾Ý¿âË÷Òý£¬¼°ÆäÓÅ¡¢È±µã¡£Õë¶ÔMySQLË÷ÒýµÄÌØµã¡¢Ó¦ÓýøÐÐÁËÏêϸµÄÃèÊö¡£·ÖÎöÁËÈçºÎ±ÜÃâMySQLÎÞ·¨Ê¹Óã¬ÈçºÎʹÓÃEXPLAIN·ÖÎö²éѯÓï¾ä£¬ÈçºÎÓÅ»¯MySQLË÷ÒýµÄÓ¦Óᣱ¾ÎÄÕª×Ô¡¶MySQL 5ȨÍþÖ¸ÄÏ¡·(3rd)µÄ8.9½Ú¡£(2007.07.0 ......
ǰÑÔ£º
±¾ÎIJûÊöµÄÊÇÒ»¿î¾¹ýÉú²ú»·¾³¼ìÑéµÄǧÍò¼¶Êý¾ÝÈ«ÎļìË÷£¨ËÑË÷ÒýÇæ£©¼Ü¹¹¡£±¾ÎÄÖ»Áгöǰ¼¸ÕµÄÄÚÈݽÚÑ¡£¬²»ÌṩȫÎÄÄÚÈÝ¡£
ÔÚDELL PowerEdge 6850·þÎñÆ÷£¨ËÄ¿Å64 λInter Xeon MP 7110N´¦ÀíÆ÷ / 8GBÄڴ棩¡¢RedHat AS4 Linux²Ù×÷ϵͳ¡¢MySQL 5.1.26¡¢MyISAM´æ´¢ÒýÇæ¡¢key_buffer=1024M»·¾³ÏÂʵ²â£¬µ¥±í1000ÍòÌõ¼Ç ......