我的表数据如下所示:
SessionRefere
http://www.google.com/url?sa=t&rct=j&q=aaa bbb&source=web&cd=1&cad=rja&sqi=2&ved=0CB4QFjAA&url=http://www.abc.com/&ei=QFR0UM-JKIrQrQfsuoG4CQ&usg=AFQjCNExYcKkcvobBbktLGNksptf1giQRw
-------------------------------------------------
http://www.google.com/reader/view/?hl=es&tab=Xq&at=RTknd_lBUUnvNqan2641EA
----------------------------------------------------
http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=5&cad=rja&ved=0CEgQFjAE&url=http://www.abc.com/ppp.aspx&ei=dmd0UOO9AYnY4QS1sYGwBw&usg=AFQjCNGIFcJUUSVpl_ZiZoSWDP2LkIagtw
这只是样本数据。有很多这样的情况。所以我想要原始网址部分在计数之前。
我使用这个查询来获取数据。
DECLARE @temp table(RefPage nvarchar(200))
insert into @temp
SELECT
CASE CHARINDEX( '?', SessionReferer)
WHEN 0 THEN SessionReferer
ELSE LEFT(SessionReferer, CHARINDEX( '?', SessionReferer) - 1) END AS RefPage
FROM Tracker WHERE [start] between '1-1-2010' and '1-1-2015' and SessionReferer<> ''
select distinct RefPage, count(*) as [VisitTime] from @temp
group by RefPage
order by [VisitTime] desc
我的结果是:
SessionRefere VisitTime
http://www.google.com/url 2
http://www.google.com/reader/view/ 1
但我想要一个结果:
SessionRefere VisitTime
http://www.google.com 3
是否有可能得到渴望的结果,或者我的方式不对?谢谢。