My table data is looks like:
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
It’s only sample data.There are many cases like this. So I want original url part before count.
I use this query to get data.
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
and my result is:
SessionRefere VisitTime
http://www.google.com/url 2
http://www.google.com/reader/view/ 1
But I want a result:
SessionRefere VisitTime
http://www.google.com 3
Is it possible to get desire result or I am in wrong way? Thanks.
Try splitting at
CHARINDEX('/',SessionReferrer,9)(I am lazily assuming all your referrers start with http:// or https://)