This question already has answers here:
SQL split values to multiple rows
                                
                                    (8个答案)
                                
                        
                                2年前关闭。
            
                    
我需要帮助。我有法定人数表

qurum table             data table
qurum_id|qurum            id|qurum1
       1|one               1|3
       2|two               2|2
       3|three             3|1
       4|four              4|7
       5|five              5|5,6
       6|six               6|4
       7|seven             7|5
where qurum_id = data.qurum1


结果必须是

qurum_id|qurum|qurum1
       1|one  |3
       2|two  |2
       3|three|1
       4|four |7
       5|five |5
     **6|six  |6
       6|six  |4**
       7|seven|5


这是查询

`SELECT qurum_id, qurum,qurum1,
        SUM(CASE WHEN DATE_FORMAT(aa.input_date, '%m') BETWEEN 01 AND 06
           THEN 1 END) AS I,
        SUM(CASE WHEN DATE_FORMAT(aa.input_date, '%m') BETWEEN 07 AND 12
           THEN 1 END) AS II
FROM qurum AS qur
INNER JOIN (SELECT id, qurum1,input_date FROM DATA ) AS aa
            ON qur.qurum_id = aa.qurum1
WHERE DATE_FORMAT(aa.input_date, '%Y') = $year
GROUP BY qurum_id
ORDER BY qurum_id`


结果为here

表中有第六行qurum1 = 6 | 7,但是我需要爆炸6 | 7,因为qurum_id 6和qurum_id 7具有不同的qurum。 Pic会show我想说的最好

最佳答案

SELECT SUBSTRING_INDEX(qurum1, ' ', 1) AS first_part,
SUBSTRING_INDEX(qurum1, ' ', -1) as second_part FROM qurum;

关于mysql - 如何 explode 具有不同ID的行? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43452474/

10-11 01:37