现有两张表
t_stat_Site表
id statSit url
1 Google http://www.google.cn/
2 百度 http://www.baidu.com/
3 其他地址 t_stat_Visitor表
id refererUrl
1 http://www.google.cn/
2 http://www.google.cn/
3 http://www.google.cn/
4 http://www.baidu.com/
5 http://www.baidu.com/
6 http://www.live.com/
7 http://www.live.com/
8 http://blog.qikoo.com/
用什么sql语句能得出结果statSit 访问数量
Google 3
百度 2
其他地址 2
t_stat_Site表
id statSit url
1 Google http://www.google.cn/
2 百度 http://www.baidu.com/
3 其他地址 t_stat_Visitor表
id refererUrl
1 http://www.google.cn/
2 http://www.google.cn/
3 http://www.google.cn/
4 http://www.baidu.com/
5 http://www.baidu.com/
6 http://www.live.com/
7 http://www.live.com/
8 http://blog.qikoo.com/
用什么sql语句能得出结果statSit 访问数量
Google 3
百度 2
其他地址 2
解决方案 »
- 提个关于webform里使用BackgroundWorker+Ajax的问题,请大侠看看想,谢谢
- radio
- asp.net中这样的项目如何进行DAL的代码编写?
- 怎么分开取020-85621454-0666
- .net入门到精通的书 谁有麻烦给我发一本非常感谢
- 我遇到了 “webcontrols配置错误”该怎么办!
- 思归老大在不?treeview显示+,-和树行线条的问题!!
- .net网站出现对象名无效的提示,怎么解决?
- asp.net关于comandtext属性的问题,跪求各路大神!!!
- 如何根据文件路径得到不带扩展名的文件名?
- windows 2003装vs2005要求win 2003 server service pack1
- 求一个分页代码,或者教下思路,请高手们帮帮忙!!!!!!
再用一个行转列
不知道對不對
GROUP BY A.statSit
select isnull(t_stat_Site.statSit,'其他地址') as statSit from t_stat_Site
right join t_stat_Visitor on t_stat_Site.url=t_stat_Visitor.refererUrl最后再用group by statSit分组统计
select statsit,a.访问数量 from (select referUrl ,count(referUrl) as 访问数量 group by referUrl ) as a,t_sta_Site where url=referUrl
select a.statsit,count(a.referUrl) as 访问数量 from (select isnull(t_stat_Site.statSit,'其他地址') as statSit,referUrl from t_stat_Site
right join t_stat_Visitor on t_stat_Site.url=t_stat_Visitor.refererUrl) as a ,t_sta_Site where url=a.referUrl
from t_stat_Site,t_stat_Visitor
where t_stat_Site.Url = t_stat_Visitor.refererUrl
group by t_stat_Visitor.refererUrl
from t_stat_Site,t_stat_Visitor
where t_stat_Site.Url *= t_stat_Visitor.refererUrl
and t_stat_Site.statsit<>'其他'
group by t_stat_Site.statSit
union
select '其他' ,count(t_stat_Visitor.refererUrl)
from t_stat_Visitor
where not exists(select t_stat_Site.url from t_stat_Site where t_stat_Visitor.refererUrl=t_stat_Site.url)
from stat_site as A inner join stat_visitor as B on A.url=B.refererurl
group by A.statsit
union
select '其他地址' as webname,count(*) as counts from
(select D.* from stat_site as C right join stat_visitor as D on C.url=D.refererurl where C.id is null) E