簡體   English   中英

使用第二個表中的值作為 mysql json_extract 中的路徑

[英]Using value from second table as path in mysql json_extract

我有兩張桌子-

table 1
---------
id      name    value
1       abc      8276

table 2
---------
id     t1_id     value
1      1         {"8271":"a","8276":"b"}

我想要以下格式的結果

Result
------
id     name      t2_value
1      abc       b

我嘗試了以下查詢,但顯示錯誤

select t2.id, t1.name, JSON_EXTRACT(t2.value, '$.t1.value') from table1 t1 left join table2 t2 on t1.id = t2.t1_id;

你這樣做的方式,你將t1.value作為字符串傳遞,而不是作為實際值。 使用CONCAT()從實際值構建字符串應該可以工作。

select t2.id, t1.name, JSON_EXTRACT(t2.value, CONCAT('$."', t1.value, '"')) from table1 t1 left join table2 t2 on t1.id = t2.t1_id;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM