Current Supply Queries

the Total Supply (T) changes all the time, when is T taken for the rewards calculation?
Is it taken at the time of calculation or during the epoch from which the rewards are from?

how can I query cardano-db-sync on the Total Supply at a certain epoch?
this query shows the current supply:

select sum (value) / 1000000 as current_supply from tx_out as tx_outer where
    	not exists
      ( select tx_out.id from tx_out inner join tx_in
          on tx_out.tx_id = tx_in.tx_out_id and tx_out.index = tx_in.tx_out_index
          where tx_outer.id = tx_out.id
      );

I tried to use this query instead to see the supply that was at epoch 249, but I get erroneous values:

select sum (value) / 1000000 as current_supply from tx_out as tx_outer 
		inner join tx on tx_outer.tx_id = tx.id 
		inner join block on tx.block_id = block.id
		where  not exists
    ( select tx_out.id from tx_out inner join tx_in
      on tx_out.tx_id = tx_in.tx_out_id and tx_out.index = tx_in.tx_out_index
      where tx_outer.id = tx_out.id )
		and block.epoch_no < 250;