Use the table's id as index for the array.
SET @row_number = 0;
Select t.* , t.calories * factors.factor result
from (
SELECT
(@row_number:=@row_number + 1) AS num,
T1.*
from test T1) t
join (
select f.* from (
Select 1 as id, 1 as factor
union Select 2, 2
Union Select 3,2
) f ) factors
on t.num = factors.id
Order by t.id;
see db fiddle
Using a json array:
SET @row_number = -1;
Select t.* ,
json_extract('{"R": [1,2,2]}' ,
Concat('$.R[',t.num,']') ) jf,
t.calories *
json_extract('{"R": [1,2,2]}' ,
Concat('$.R[',t.num,']') ) result
from (
SELECT
(@row_number:=@row_number + 1) AS num,
T1.*
from test T1) t
order by t.id;
Db fiddle
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…