Group by and the last event record


I have a bucket named log which has a fields

  • event_date
  • session_id
  • info`

I’m trying to run a query which looks like
select ??? from log
group by session_id

My problem is that each session_id can have many event_date-s. In my group by N1QL query I want to select all info fields that matches to the MAX(event_date).

I wish I could post here what I’ve tried but there is nothing really to post.

Thanks for any help.

Can you post the desired results.

Here is the query that works for beer-sample You can adapt it to your JSON.

SELECT t1.code, t2 FROM
select brewery_id, meta().id docid, max(code) code
from `beer-sample`
group by brewery_id, meta().id
having code = max(code)) t1 INNER JOIN `beer-sample` t2 ON KEYS t1.docid