• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
pangzipangpang走过的路
博客园    首页    新随笔    联系   管理    订阅  订阅

实用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 
posted @ 2009-03-12 16:12  pangzi  阅读(269)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3