1

Hi I am having a small issue doing the following. I have a table call analytics. that's all working fine. However when I run the following query

SELECT * FROM analytics 
WHERE  stamp > date_sub(now(), interval 1 day)
GROUP BY sessionkey;

i get

 '20','n2zurgy5wcmiymbcla1hb1fnj0lu5km','2',NULL,'/','2015-06-26 07:14:05'

Which is the last insert for that sessionkey.

Now here is the issue - It's not quite what I want, you see my aim is to get the total of unique sessions for that day and return the total.

I have tried the following:

SELECT * FROM analytics 
WHERE  stamp > date_sub(now(), interval 1 day) 
GROUP BY sessionkey AND date(stamp);

But also without luck, even putting count(*) around the * does not seem to help.

So I believe I need to count around the select statement or something like this, but I am not sure. Could someone please point me in the right direction.

user12009
  • 11
  • 2
RussellHarrower
  • 6,470
  • 21
  • 102
  • 204
  • So are you using PHP to deal with the output? If so, you could put the query's return value in an array, and use PHP to count the number of items in the array. – kittykittybangbang Jun 25 '15 at 22:39
  • It is impossible to use a field in WHERE and GROUP BY clauses. Move conditions on date(stamp) to HAVING clause – Naeel Maqsudov Jun 25 '15 at 22:48
  • why not select three columns (last being count(*) ) so that your `group by` even makes sense. And I have no idea what @NaeelMaqsudov is thinking ! – Drew Jun 25 '15 at 23:02

0 Answers0