I have the following table with group members count:
CREATE TABLE "group_members_count" (
group_id INTEGER,
time TIMESTAMP,
members_count INTEGER
)
I want to query members count for specific group and time interval (from, to) with custom period.
I wrote the following query:
SELECT
"group_id",
date_trunc('day', "time") as period,
max(count) as value
FROM
"group_members_count"
WHERE
"channel_id" IN (123, 124) AND ("time"::date >= '2017-11-02' AND "time"::date <= '2017-11-02')
GROUP BY
"period", "group_id"
ORDER BY
"group_id", "period"
As expected, I will get the maximum value per day, but I need the latest.
max(("time"::date)?..