max() calculates the maximum across a group of values. For example,
-- Finds the most recent timestamp in the table.
SELECT max(signed_at)
FROM blockchains.all_chains
min() calculates the minimum across a group of values. For example,
-- Finds the first timestamp in the table.
SELECT min(signed_at)
FROM blockchains.all_chains
To find the corresponding transaction hash (tx_hash) for the max and min signed_at 👇
-- Finds the most recent timestamp in the table.
SELECT max(signed_at), tx_hash
FROM blockchains.all_chains
GROUP BY tx_hash
-- Finds the most recent timestamp in the table.
SELECT min(signed_at), tx_hash
FROM blockchains.all_chains
GROUP BY tx_hash
If you need a non-aggregate function to choose a maximum or minimum of two values, use greatest:
-- Maximum
SELECT greatest(a, b) FROM table
--Minimum
SELECT least(a, b) FROM table
View all other aggregate functions here