Hi, I have a table ```{ "schemaName": "balance",...
# general
j
Hi, I have a table
Copy code
{
  "schemaName": "balance",
  "dimensionFieldSpecs": [
    {
      "name": "account_id",
      "dataType": "STRING"
    },
    {
      "name": "token_id",
      "dataType": "STRING"
    },
    {
      "name": "balance",
      "dataType": "LONG"
    }
  ],
  "dateTimeFieldSpecs": [
    {
      "name": "consensus_timestamp",
      "dataType": "LONG",
      "format": "1:NANOSECONDS:EPOCH",
      "granularity": "1:NANOSECONDS"
    }
  ]
}
I am trying to find out the most recent balance for each account_id & token_id pairs. I can't seem to see a easy way to do that without many queries?
k
lastWithTime?
j
thanks I just found that in docs đŸ™‚
select account_id, token_id, LASTWITHTIME(balance,consensus_timestamp,'long'), max(consensus_timestamp) from balance group by account_id, token_id order by account_id
seems to work
k
cool
If that’s the only query you need to address, upsert might be better?