Skip to content
Advertisement

How do I get the matching id for every record?

My table is called platform_statuses, here is its schema:

And this is my query, I would like to also get the matching id for the returned records.

Also note that the abs function you see in the query is a custom one I got off this answer. Here is its definition:

Advertisement

Answer

I understand that, for each account and day, you want the record with the greatest timediff. If so, you can use distinct on() directly on your existing subquery:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement