MySQLÖÐÓÃselectʵÏÖTOP N¹¦ÄÜ ¼°·ÖÒ³
MySQLÖÐÓÃselectʵÏÖTOP N¹¦ÄÜ
ÏÈ˵¼¸¸ö¹Ø¼ü×Ö£º
distinct ·µ»Ø²»Öظ´µÄ¶àÁÐ
count() ¼ÆÊý
limit m,n µÚm¸öÆðn¸ö
ÄÇô£¬Èç¹ûÐèÒª²éÕÒÃûΪcolµÄijһ¸öÁеÄTop N£¬²¢Áгö¶ÔÓ¦µÄÖµµÄselectÓï¾ä¾ÍÈçÏ£º
select dinstinct(col),count(col) from tablename group by 1 order by 2 desc limit 0,N;
Ïà¹ØÎĵµ£º
×î½üÏëÔÚ·þÎñÆ÷ÉÏÊÔÊÔMySQL5.1µÄ·ÖÇø£¬ÓÚÊǾÍÏë×Å×°¸öMySQL5.1£¬¾¹ýÍ´¿àµÄÒ»¶Î¾Àúºó£¬ÖÕÓÚÕÒ¸öÏÂÃæ×°¸öºÜºÃµÄ½Ì³Ì£¬ÌûÉÏÀ´±¸Íü¡£
1¡¢MySQLÃâ°²×°°æ/¶þ½øÖÆ°æÈí¼þ£¬²»ÓñàÒ룬ÏÂÔصØÖ·£º
http://dev.mysql.com/downloads/
Îļþ¸ñʽ£ºMYSQL-VERSION-OS.tar.gz
2¡ ......
(1)µÇ½µ½mysql
C:\Documents and Settings\Administrator>mysql -h localhost -u root -p
Enter password: *****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 69
Server version: 5.0.51a-community-nt MySQL Community Edition (GPL)
Type 'help;' or '\h' fo ......
Mysql Explain Ïê½â
Ò».Óï·¨
explain < table_name >
ÀýÈç: explain select * from t3 where id=3952602;
¶þ.explainÊä³ö½âÊÍ
+----+-------------+-------+-------+-------------------+---------+---------+-------+------+-------+
| id | select_type | table | type | possible_keys &nb ......
mysqlÖÐchar¡¢varchar¡¢nvarcharÊý¾ÝÀàÐ͵ÄÓ÷¨Çø±ð:
˵Ã÷:
1¡¢char:
¹Ì¶¨³¤¶ÈµÄ·Ç Unicode ×Ö·ûÊý¾Ý£¬×î´ó³¤¶ÈΪ 8,000 ¸ö×Ö·û¡£
2¡¢varchar£º
¿É±ä³¤¶ÈµÄ·Ç Unicode Êý¾Ý£¬×Ϊ 8,000 ¸ö×Ö·û¡£
3¡¢nvarchar£º
¿É±ä³¤¶È Unicode Êý¾Ý£¬Æä×î´ó³¤¶ÈΪ 4,000 ×Ö·û¡£  ......