牛逼plus
每天一个知识点
tableA
id | num |
1 | 1001,1002 |
2 | 1002 |
tableB
id | num | name |
1 | 1001 | A |
2 | 1002 | B |
想要的结果:
id | name |
1 | A,B |
2 | B |
SELECT
*(其他字段),
(select group_concat(b.name) from tableB b where FIND_IN_SET(b.num,a.num)) name
FROM tableA a
牛逼plus
每天一个知识点
tableA
id | num |
1 | 1001,1002 |
2 | 1002 |
tableB
id | num | name |
1 | 1001 | A |
2 | 1002 | B |
想要的结果:
id | name |
1 | A,B |
2 | B |
SELECT
*(其他字段),
(select group_concat(b.name) from tableB b where FIND_IN_SET(b.num,a.num)) name
FROM tableA a