SQLTeam.com | Weblogs | Forums

SQL Help for multiple conditions

Hi All , Please help me with a query where table is in particular format

Visitor_id | page | next page|
I want to the count or list of visitors who visited a particular page (let say X) then visited another page (let say Y)
which functions would be useful

This perhaps?

SELECT Visitor_id
FROM MyTable
WHERE page = 'X'
      AND [next page] = 'Y'

Change "SELECT Visitor_id" to "SELECT COUNT(*) AS MyCount" for a Count of the number of such visitors

1 Like


this will give result if Y is just after X ,.... if not just next page.. means if a visitor is visiting after Z,A and then X.. how to solve that

I doubt that you can do that easily with the structure you have. maybe a Recursive CTE would do it ...

We solve that by having a Session No. and DateTime as columns in the Log Table, rather than ThisPage, NextPage, so we can find any Session that has PageX and then, later on in the session, PageY by a simple self-referencing JOIN, or EXISTS, rather than having to follow a linked-list

1 Like