PostgreSQL
 sql >> Datenbank >  >> RDS >> PostgreSQL

SQL-Abfrage zum Abrufen der neuesten Zeile für jede Instanz eines bestimmten Schlüssels

Versuchen Sie Folgendes:

Select u.[username]
      ,u.[ip]
      ,q.[time_stamp]
From [users] As u
Inner Join (
    Select [username]
          ,max(time_stamp) as [time_stamp]
    From [users]
    Group By [username]) As [q]
On u.username = q.username
And u.time_stamp = q.time_stamp