select historic_betfair_win_prices.sf_name,historic_runners.finish_position,historic_runners.official_rating,historic_betfair_win_prices.date, historic_betfair_win_prices.bsp,
if(finish_position = 1 , @b:=@b+1,@b:=@b) opening_position,
if(finish_position = 1 , @last_op:=official_rating,@last_op:=@last_op)last_opening_position,
cast(if(@b = 0 or finish_position = 1,0,@last_op - official_rating) as decimal(10,2)) diff
from historic_runners
inner join historic_betfair_win_prices on historic_betfair_win_prices.runner_id = historic_runners.runner_id and historic_betfair_win_prices.sf_race_id = historic_runners.race_id
cross join (select @b:=0, @last_op :=0) b
where historic_betfair_win_prices.sf_name = "Camanche Grey"
limit 50
I want to hide
opening_position, last_opening_position
columns from the output result. My Mysql version 8.0.18
Use a subquery
select sf_name,finish_position,official_rating,date,bsp,diff from
(
select historic_betfair_win_prices.sf_name,historic_runners.finish_position,historic_runners.official_rating,historic_betfair_win_prices.date, historic_betfair_win_prices.bsp,
if(finish_position = 1 , @b:=@b+1,@b:=@b) opening_position,
if(finish_position = 1 , @last_op:=official_rating,@last_op:=@last_op)last_opening_position,
cast(if(@b = 0 or finish_position = 1,0,@last_op - official_rating) as decimal(10,2)) diff
from historic_runners
inner join historic_betfair_win_prices on historic_betfair_win_prices.runner_id = historic_runners.runner_id and historic_betfair_win_prices.sf_race_id = historic_runners.race_id
cross join (select @b:=0, @last_op :=0) b
where historic_betfair_win_prices.sf_name = "Camanche Grey"
limit 50
)A
select historic_betfair_win_prices.sf_name,
historic_runners.finish_position,
historic_runners.official_rating,
historic_betfair_win_prices.date,
historic_betfair_win_prices.bsp,
cast(if((@b := if(finish_position = 1 ,
@b+1,
@b))= 0 or finish_position = 1,
0,
(@last_op := if(finish_position = 1 ,
official_rating,
@last_op)) - official_rating) as decimal(10,2)) difffrom historic_runners
inner join historic_betfair_win_prices on historic_betfair_win_prices.runner_id = historic_runners.runner_id and historic_betfair_win_prices.sf_race_id = historic_runners.race_id
cross join (select @b:=0, @last_op :=0) b
where historic_betfair_win_prices.sf_name = "Camanche Grey"
limit 50
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.