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

MySQLÈçºÎÀûÓÃË÷ÒýÓÅ»¯ORDER BYÅÅÐòÓï¾ä


MySQLË÷Òýͨ³£ÊDZ»ÓÃÓÚÌá¸ßWHEREÌõ¼þµÄÊý¾ÝÐÐÆ¥Åä»òÕßÖ´ÐÐÁª½á²Ù×÷ʱƥÅäÆäËü±íµÄÊý¾ÝÐеÄËÑË÷Ëٶȡ£
MySQLÒ²ÄÜÀûÓÃË÷ÒýÀ´¿ìËÙµØÖ´ÐÐORDER BYºÍGROUP BYÓï¾äµÄÅÅÐòºÍ·Ö×é²Ù×÷¡£
ͨ¹ýË÷ÒýÓÅ»¯À´ÊµÏÖMySQLµÄORDER BYÓï¾äÓÅ»¯£º
1¡¢ORDER BYµÄË÷ÒýÓÅ»¯¡£Èç¹ûÒ»¸öSQLÓï¾äÐÎÈ磺
SELECT [column1],[column2],…. from [TABLE] ORDER BY [sort];
ÔÚ[sort]Õâ¸öÀ¸Î»ÉϽ¨Á¢Ë÷Òý¾Í¿ÉÒÔʵÏÖÀûÓÃË÷Òý½øÐÐorder by ÓÅ»¯¡£
2¡¢WHERE + ORDER BYµÄË÷ÒýÓÅ»¯£¬ÐÎÈ磺
SELECT [column1],[column2],…. from [TABLE] WHERE [columnX] = [value] ORDER BY [sort];
½¨Á¢Ò»¸öÁªºÏË÷Òý(columnX,sort)À´ÊµÏÖorder by ÓÅ»¯¡£
×¢Ò⣺Èç¹ûcolumnX¶ÔÓ¦¶à¸öÖµ£¬ÈçÏÂÃæÓï¾ä¾ÍÎÞ·¨ÀûÓÃË÷ÒýÀ´ÊµÏÖorder byµÄÓÅ»¯
SELECT [column1],[column2],…. from [TABLE] WHERE [columnX] IN ([value1],[value2],…) ORDER BY[sort];
3¡¢WHERE+ ¶à¸ö×Ö¶ÎORDER BY
SELECT * from [table] WHERE uid=1 ORDER x,y LIMIT 0,10;
½¨Á¢Ë÷Òý(uid,x,y)ʵÏÖorder byµÄÓÅ»¯,±È½¨Á¢(x,y,uid)Ë÷ÒýЧ¹ûÒªºÃµÃ¶à¡£
MySQL Order By²»ÄÜʹÓÃË÷ÒýÀ´ÓÅ»¯ÅÅÐòµÄÇé¿ö
* ¶Ô²»Í¬µÄË÷Òý¼ü×ö ORDER BY £º(key1,key2·Ö±ð½¨Á¢Ë÷Òý)
SELECT * from t1 ORDER BY key1, key2;
* ÔÚ·ÇÁ¬ÐøµÄË÷Òý¼ü²¿·ÖÉÏ×ö ORDER BY£º(key_part1,key_part2½¨Á¢ÁªºÏË÷Òý;key2½¨Á¢Ë÷Òý)
SELECT * from t1 WHERE key2=constant ORDER BY key_part2;
* ͬʱʹÓÃÁË ASC ºÍ DESC£º(key_part1,key_part2½¨Á¢ÁªºÏË÷Òý)
SELECT * from t1 ORDER BY key_part1 DESC, key_part2 ASC;
* ÓÃÓÚËÑË÷¼Ç¼µÄË÷Òý¼üºÍ×ö ORDER BY µÄ²»ÊÇͬһ¸ö£º(key1,key2·Ö±ð½¨Á¢Ë÷Òý)
SELECT * from t1 WHERE key2=constant ORDER BY key1;
* Èç¹ûÔÚWHEREºÍORDER BYµÄÀ¸Î»ÉÏÓ¦Óñí´ïʽ(º¯Êý)ʱ£¬ÔòÎÞ·¨ÀûÓÃË÷ÒýÀ´ÊµÏÖorder byµÄÓÅ»¯
SELECT * from t1 ORDER BY YEAR(logindate) LIMIT 0,10;
ÌرðÌáʾ:
1>mysqlÒ»´Î²éѯֻÄÜʹÓÃÒ»¸öË÷Òý¡£Èç¹ûÒª¶Ô¶à¸ö×Ö¶ÎʹÓÃË÷Òý£¬½¨Á¢¸´ºÏË÷Òý¡£
2>ÔÚORDER BY²Ù×÷ÖУ¬MySQLÖ»ÓÐÔÚÅÅÐòÌõ¼þ²»ÊÇÒ»¸ö²éѯÌõ¼þ±í´ïʽµÄÇé¿öϲÅʹÓÃË÷Òý¡£


Ïà¹ØÎĵµ£º

MySql時間º¯數


Ò»¡¢MySQL »ñµÃµ±Ç°ÈÕÆÚʱ¼ä º¯Êý
1.1 »ñµÃµ±Ç°ÈÕÆÚ+ʱ¼ä£¨date + time£©º¯Êý£ºnow()
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2008-08-08 22:20:46 |
+---------------------+
³ýÁË now() º¯ÊýÄÜ»ñµÃµ±Ç°µÄÈÕÆÚʱ¼äÍ⣬MySQL Öл¹ÓÐÏÂÃæµÄº¯Êý£º
......

VC++ÔÚWindowsƽ̨Á¬½ÓMySqlÊý¾Ý¿â

       ÒÔÇ°ÓùßÁËMSSQL£¬VC++ÓÐÇ¿´óµÄADOÖ§³Ömssql£¬·½±ã°¡£¬²»¹ÜÊÇÁ¬½Ó£¬²Ù×÷µÈ¶¼ÊÇÀÊÀÊÉÏÊÖ°¡¡£µ«ÊÇÏÖÔÚͻȻҪÓÃMySqlÁË£¬¿ªÊ¼Ã»ÓÐmssqlÄÇÑùµÄ²Ù×÷½çÃ棬ÎÒÕæÓеãÅų⡣°¥£¬Ã»°ì·¨£¬¹«Ë¾ÒªÇó£¬Ö»ÄÜÑо¿MySqlÔõôÓÃÁË¡£
       ¸Õ¿ªÊ¼¾ÍÓöµ½ÁËÒ»¸ö»ù±¾µÄÎÊ ......

mysqlµÄcardinalityÔÚmyisamºÍinnodbÖеIJ»Í¬

Ïêϸ½âÊͺÍÀý×Ó¼ûÏÂÁÐÎÄÕ£º
http://www.mysqlperformanceblog.com/2008/09/03/analyze-myisam-vs-innodb/
http://www.penglixun.com/work/database/mysql_show_index_cardinality.html
£¨1£©cardinalityÓ°Ïìmysql optimizer¶ÔË÷ÒýµÄÑ¡È¡
£¨2£©¿ÉÒÔͨ¹ýshow index from table_nameÀ´²é¿´±íµÄË÷ÒýºÍcardinality
£¨3£©in ......

ʹÓÃhibernateÓëmysqlʱÊý¾Ý²»ÄܲåÈëµÄÔ­Òò¼°½â¾ö°ì·¨

1.±³¾°     
      Ö®Ç°´ÓûÓùýhibernate£¬Òò´ËÔÚÍøÉÏËÑÁËÒ»ÏÂhibernate¿ìËÙÈëÃÅ·½ÃæµÄÐÅÏ¢£¬×îºóÎÒ°´ÕÕ¡¶Myeclipse Hibernate ¿ìËÙÈëÃÅ ÖÐÎÄ°æ¡·£¨CSDN£¬°Ù¶ÈÎĿⶼÓУ©Ò»ÎÄ¿ªÊ¼ÁËÎÒµÄhibernateÖ®Âã¨ÎªÏîÄ¿×ö¼¼Êõ×¼±¸£©¡£
      ÏÂÃ ......

MysqlÖ®EXPLAINÏÔʾusing filesort

EXPLAIN ÊÇmysql½âÊÍselect²éѯµÄÒ»¸ö¹Ø¼ü×Ö,¿ÉÒԺܷ½±ãµÄÓÃÓÚµ÷ÊÔ
Óï·¨¸ñʽÈçÏÂ
EXPLAIN tbl_name
»òÕß:
EXPLAIN SELECT select_options
EXPLAIN Óï¾ä¿ÉÒÔ±»µ±×÷ DESCRIBE µÄͬÒå´ÊÀ´Óã¬Ò²¿ÉÒÔÓÃÀ´»ñÈ¡Ò»¸öMySQLÒªÖ´ÐÐµÄ SELECT Óï¾äµÄÏà¹ØÐÅÏ¢¡£
EXPLAIN tbl_name Óï·¨ºÍ DESCRIBE tbl_name »ò SHOW COLUMNS ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ