MYSQL如何使用Table_1中的JSON数组中存储的值从Table_2中提取数据,然后将Table_1中的数组替换为Table_2中的数据

时间:2017-10-04 20:57:17

标签: mysql

我想从AssignedTo中的JSON数组Table_1中提取ID 使用该数据从Table_2中提取 然后将AssignedToTable_1中的数据替换为Table_2

中的名称
Table_1
    JobID       Table_2_ID
     101     [403, 404, 405]
     102     [406, 407, 408]
     103     [409, 410, 411]


Table_2 
        personID     FirstName     LastName 
        403          Josh          Adams
        404          Mary          Poppins
        405          Mickey        Mouse
        406          Donald        Duck
        407          Pete          Schmit
        408          Anna          Bagel
        409          Jake          Crabs
        410          Sponge        Bob
        411          Stuart        Little

SELECT JobID, AssignedTo (REPLACE AssignedTo[0-2] WITH 
CONCAT(Table_2.FirstName, ' ', Table_2.LastName 
WHERE Table_1.AssignedTo = Table_2.personID)
FROM Table_1, Table_2

结果:

JobID   AssignedTo
101     [Josh Adams, Mary Poppins, Micky Mouse]
102     [Donald Duck, Pete Schmit, Anna Bagel]
103     [Jake Crabs, Sponge Bob, Stuart Little]

0 个答案:

没有答案