如何在Mysql中隐藏输出结果中的列?
我想躲起来 打开位置,最后打开位置 输出结果中的列。My Mysql 8.0.18版使用子查询如何在Mysql中隐藏输出结果中的列?,mysql,sql,Mysql,Sql,我想躲起来 打开位置,最后打开位置 输出结果中的列。My Mysql 8.0.18版使用子查询 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_positio
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
删除它们,并将计算移到
diff
字段表达式中。@ZajjithVedha。我建议你问一个新问题。您可以在没有变量的情况下随心所欲——现在MySQL中不推荐使用这些变量。提供示例数据、所需结果以及对要实现的逻辑的解释。从代码结果中,一些diff值更改为0.00,一些更改为NULL。所以diff列只有0.00和NULL。但是我从上面的代码中得到了不同的值。@ZajjithVedha是的,我在插入时出错了-我将进行编辑。其中一些变为NULL,我看不到可能导致将NUUL赋值给任何变量的条件。@ZajjithVedha已编辑,请检查。
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