title: How to get most recent data from DynamoDB for each primary partition key in PartiQL
body: <p>inspired from this <a href="https://stackoverflow.com/questions/56136226/how-to-get-most-recent-data-from-dynamodb-for-each-primary-partition-key">How to get most recent data from DynamoDB for each primary partition key?</a></p>
  <p>I have a table in dynamodb. It stores account stats. It's possible that the account stats will be updated several times per day. So table records may look like:</p>
  <p>+------------+--------------+-------+-------+<br />
  | account_id | record_id    | views | stars |<br />
  +------------+--------------+-------+-------+<br />
  | 3          | 2019/03/16/1 | 29    | 3     |<br />
  +------------+--------------+-------+-------+<br />
  | 2          | 2019/03/16/2 | 130   | 21    |<br />
  +------------+--------------+-------+-------+<br />
  | 1          | 2019/03/16/3 | 12    | 2     |<br />
  +------------+--------------+-------+-------+<br />
  | 2          | 2019/03/16/1 | 57    | 12    |<br />
  +------------+--------------+-------+-------+<br />
  | 1          | 2019/03/16/2 | 8     | 2     |<br />
  +------------+--------------+-------+-------+<br />
  | 1          | 2019/03/16/1 | 3     | 0     |<br />
  +------------+--------------+-------+-------+<br />
  account_id is a primary partition key. record_id is a primary sort key</p>
  <p>How I can get only latest records for each of the account_ids? So from the example above I expect to get:</p>
  <p>+------------+--------------+-------+-------+<br />
  | account_id | record_id    | views | stars |<br />
  +------------+--------------+-------+-------+<br />
  | 3          | 2019/03/16/1 | 29    | 3     |<br />
  +------------+--------------+-------+-------+<br />
  | 2          | 2019/03/16/2 | 130   | 21    |<br />
  +------------+--------------+-------+-------+<br />
  | 1          | 2019/03/16/3 | 12    | 2     |<br />
  +------------+--------------+-------+-------+<br />
  This data is convenient to use for a reporting purposes.</p>