2011-01-11 62 views
0
table links 
id  url 
1  http://www.domain.hk/index.php?main_page=index&cPath=8 
3  http://www.domain.com/index.php?main_page=index&cPath=3 
6  http://www.domain.com/index.php?main_page=index&cPath=8 
8  http://www.domain.hk/index.php?main_page=index&cPath=7&language=tc 
9  http://www.domain.com/index.php?main_page=index&cPath=3 

如何計算從外地url使用regex的相同cPath id數量和相同cPath iddomain多少?MySQL的正則表達式計數

我想要的結果是這樣的:

CPATH:8總:2 HK:1 COM:1

CPATH:3總:2 COM:2

CPATH:7總:1 com:1

謝謝 很多。

+0

想要解決所有的錯字嗎? – ajreal 2011-01-11 09:41:37

回答

1

我不認爲我有足夠的知識產生hk:1, com:1

,但這更接近我可以生成

select 
    substring_index(substring_index(url, 'cPath=', -1), '&', 1) as cpath, 
    count(*) as total, 
    substring_index(substring_index(url, '/', 3), '.', -1) as tld 
from links 
group by cpath, tld; 
 
| cpath | count(*) | tld | 
+-------+----------+------+ 
| 3  |  2 | com | 
| 7  |  1 | hk | 
| 8  |  1 | com | 
| 8  |  1 | hk | 
+-------+----------+------+

PShk,com不是域名,但TLD