Hello, I am looking for a n1ql query where I select data sorting it by date but listing those with the same name together.
IE:
{
{ date:0, name: “John”}
{date:1, name: “Peter”}
{date:2, name: “John”}
{date:3, name:“Peter”}
}
What I want is: The one with the newest date go first followed by those with the same name ordered by date, then the next newer date followed by those with the same name ordered by date and so on.
[
{date:3, name:“Peter”}
{date:1, name: “Peter”}
{date:2, name: “John”}
{ date:0, name: “John”}
]
They are ORDER BY date DESC but those which have the same name are selected in togheter.
Thanks
Thanks for your reply,
I’ve already tried that with no success that is why I asked. I also tried nested SELECT but I haven’t find a solution yet, maybe because it is not possible.
SELECT RAW uv
FROM (SELECT ARRAY_AGG(d) AS av
FROM default AS d
WHERE d.name > ""
GROUP BY d.name
ORDER BY MAX(d.date) DESC) AS t
UNNEST (SELECT RAW t1 FROM t.av AS t1 ORDER BY t1.date DESC) AS uv;