2011-01-11 3 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 홍콩 : 1 닷컴 : 1

CPATH : 3 총 : 2 닷컴 : 2

CPATH : 7 총 : 1 co.kr : 1

많이.

+0

먼저 모든 오자를 수정 하시겠습니까? – ajreal

+0

오, 그래. 고맙습니다. – love

답변

1

내가 PShk,com

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 | 
+-------+----------+------+

생성 할 수 있습니다 내가 hk:1, com:1

을 생성 할 수있는 충분한 지식을 가지고 있지만 가까이 생각하지 않는 것은 도메인 이름 만 TLD

아니다