sql - MySQL Subquery / Query Issue -
i'm having mental block query, i'm trying return max date , maximum time , order of identity. appreciate if can add pair of eyes type of query :
data set
identity, date, time, website 10, 5/10/15, 1, google.com 10, 5/10/15, 3, google.com 10, 5/10/15, 10, google.com 25, 5/11/15, 1, yahoo.com 25, 5/11/15, 15, yahoo.com
expected result
10, 5/10/15, 10, google.com 25, 5/11/15, 15, yahoo.com
current query
select distinct *, max(datetime) maxdate, max(time), identity identity_track group identity order maxdate desc
something this?
select identity, max(date), max(time), website identity_track group website;
demo here: http://sqlfiddle.com/#!9/5cadf/1
you can order of fields want.
also, expected output posted doesn't line seems you're attempting do.
edit
updated query based on additional information.
select t.identity, t.date, max(t.time), t.website t inner join (select identity, website, max(date) d t group identity, website) q on t.identity = q.identity , t.website = q.website , q.d = t.date group t.identity, t.website, t.date
this 1 should give users identity, pages visited, last time visited page, , amount of time spent in visit on last visit.
Comments
Post a Comment