Óï¾äÈçÏ£¬ÆäÖÐ×Ö¶ÎÃû´æ´¢µÄÊÇÍøÖ·£¬Õû¸ö´úÂëµÄ¹¦ÄܾÍÊÇͳ¼ÆÏàͬÍøÕ¾µÄ´ÎÊý£¬
±ÈÈç˵ÓÐÁ½Ìõ¼Ç¼,Ò»¸öÊÇhttp://www.baidu.com/ ÁíÒ»¸öÊÇhttp://www.baidu.com/a/b/c/d/
Õâ¶Î´úÂë¾Í»á°´ÕÕµãºÅ"."µÄλÖðÑ"baidu"È¡³öÀ´£¬ÄÇôbaiduµÄ·ÃÎÊ´ÎÊýÊÇ2£¬¾ÍÊÇÕâô¸öЧ¹û
ÏÖÔÚµÄÎÊÌâ¾ÍÊÇMySQLûÓÐÌṩCHARINDEXº¯Êý£¬ÎÒËÑÁËһϣ¬MySQLÀïÓиöinstrº¯Êý£¬µ«ÊÇÕâ¸öº¯ÊýÖ»ÄÜÓÐÁ½¸ö²ÎÊý£¬
µ«ÊÇ×¢ÒâÕâ¸ö´úÂëÖÐÓм¸¸öCHARINDEXÀïÊÇÈý¸ö²ÎÊý£¬Õâ¾ÍÊÇ×î´óµÄÎÊÌâ¡£
SQL code:
SELECT top 6
COUNT
(
SUBSTRING
(
×Ö¶ÎÃû,
CHARINDEX('.',×Ö¶ÎÃû)+1,CHARINDEX('.',×Ö¶ÎÃû,CHARINDEX('.',×Ö¶ÎÃû)+1)-CHARINDEX('.',×Ö¶ÎÃû)-1
)
)
as nCount,
SUBSTRING
(
×Ö¶ÎÃû,
CHARINDEX('.',×Ö¶ÎÃû)+1,CHARINDEX('.',×Ö¶ÎÃû,CHARINDEX('.',×Ö¶ÎÃû)+1)-CHARINDEX('.',×Ö¶ÎÃû)-1
)
as address
from ±íÃû
GROUP BY
SUBSTRING
(
×Ö¶ÎÃû,
CHARINDEX('.',×Ö¶ÎÃû)+1,
CHARINDEX('.',×Ö¶ÎÃû,CHARINDEX('.',×Ö¶ÎÃû)+1)-CHARINDEX('.',×Ö¶ÎÃû)-1
)
order by count(*) desc
SQL code:
mysql> select * from url;
+-------------------------------+
| url |
+-------------------------------+
| http://www.baidu.com/ |
| http://www.baidu.com/a/b/c/d/ |
| http://www.sina.com