2011-01-11 80 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