Query editor
with maintable as (with t1 as (selectdate_trunc ('day', minute) as date,avg(price) as pricefrom prices.usdwhere symbol = 'BTC'and date_trunc ('day', minute) between cast('2011-11-30' as date) and cast('2016-08-31' as date)group by date_trunc ('day', minute)order by date_trunc ('day', minute) desc),peaktable as (selectmax(price) as peakfrom t1where date between cast('2012-11-28' as date) and cast('2016-08-31' as date)),lowtable as (selectmin(price) as lowfrom t1where date between cast('2013-11-01' as date) and cast('2016-08-31' as date)),firsthalvingtable as (selectdate as firsthalvingfrom t1where date = cast('2012-11-28' as date)),secondhalvingtable as (selectdate as secondhalvingfrom t1where date = cast('2016-07-09' as date))selectdate, price, peak, lowfrom t1, peaktable, lowtableunionselectfirsthalving, price, peak, lowfrom t1, peaktable, lowtable, firsthalvingtableunionselectsecondhalving, price, peak, lowfrom t1, peaktable, lowtable, secondhalvingtable)selectdate, price, peak, low,-(1-low/peak)*100 as drawdown,(peak/12.2-1)*100 as h2p,-(1-652.48/peak)*100 as p2h,(652.48/low-1) *100 as l2hfrom maintable