WITHclause defines a common table expression (CTE), which is a temporary named result set. The definition of a CTE includes its name, an optional list of column names, and a query expression (that is, a
[ WITH <cte_name> [ ( <cte_column1>, <cte_column2>, ... ) ]
AS ( <query> )
[ WITH <cte_name> [ ( <cte_column1>, <cte_column2>, ... ) ] AS ( <query> ) ]
A temporary named result set for use in the statement that defines the CTE.
<cte_name>: The name of the CTE you are defining. The CTE must have a unique name within a given query.
<cte_column#>: The names of the columns from the query that defines the CTE.
AS <query>: The query (
SELECT) statement that defines the CTE.
Get Average ETH withdrawn per block after the Ethereum Shanghai Upgrade
with eth_withdrawn as (
select eth.withdrawals.block_number, SUM(amount) as amount_gwei
group by eth.withdrawals.block_number
order by block_number asc)
select AVG(amount_gwei / 1e9) as amount_eth