实用SQL:访问来源统计
因为要统计网站访问日志的来源,于是写了以下SQL,查询的结果基本OK,还有部分特殊的域名及效率有待以后改善。![]()
select substring(count_from_url,charindex('.',count_from_url)+1,
(case when (charindex('/',count_from_url,9))=0
then len(count_from_url)-charindex('.',count_from_url)
when (charindex('/',count_from_url,9))>0
then charindex('/',count_from_url,9)-charindex('.',count_from_url)-1
end)),
count(0) aa
from table_count where some_expression
group by
substring(count_from_url,charindex('.',count_from_url)+1,
(case when (charindex('/',count_from_url,9))=0
then len(count_from_url)-charindex('.',count_from_url)
when (charindex('/',count_from_url,9))>0
then charindex('/',count_from_url,9)-charindex('.',count_from_url)-1
end))
order by aa desc
(case when (charindex('/',count_from_url,9))=0
then len(count_from_url)-charindex('.',count_from_url)
when (charindex('/',count_from_url,9))>0
then charindex('/',count_from_url,9)-charindex('.',count_from_url)-1
end)),
count(0) aa
from table_count where some_expression
group by
substring(count_from_url,charindex('.',count_from_url)+1,
(case when (charindex('/',count_from_url,9))=0
then len(count_from_url)-charindex('.',count_from_url)
when (charindex('/',count_from_url,9))>0
then charindex('/',count_from_url,9)-charindex('.',count_from_url)-1
end))
order by aa desc
浙公网安备 33010602011771号