php - Using SQL to COUNT the most recent rows only -


i'm trying build analytic page, , i've encountered problem; users visit pages based on session, if session expires provided new one.

i'm trying determine way count number of users last session on page using query:

select distinct (select max(session) analytics b a.session=b.session) session,(select max(distinct location) analytics c c.session=a.session) locale analytics 

that query return results follows:

session |           location             ------------------------------------------ 1       | http://random-page.io/index.html -- same session, first entry           1       | http://random-page.io/index.html -- same session, second entry         1       | http://random-page.io/index.html -- same session, last entry   <- we're trying count         2       | http://random-page.io/index.html -- same session, first entry         2       | http://random-page.io/index.html -- same session, last entry <- we're trying count           3       | http://random-page.io/index.html -- 1 session, presumably serves last , first entry.. last matters  <- we're trying count 4       | http://random-page.io/drafts.html -- 1 session  <- we're trying count 5       | http://random-page.io/elements.html -- 1 session  <- we're trying count 

what want able able count rows session ends only, , truncate duplicate results (by using group , count) query returns following:

count   |           location             ------------------------------------------ 3       | http://random-page.io/index.html -- count 3 , not 5 because there 3 sessions in last entry assigned session http://...index.html 1       | http://random-page.io/drafts.html -- catch drift 1       | http://random-page.io/elements.html  -- coolio <3 

is @ possible?

you can give try:

select   count(*) count,   a.lastentry location (         select            session,            substring_index(group_concat(location), ',', -1) lastentry         analytics          group session     ) group a.lastentry; 

here sqlfiddle.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -