@
find_in_set和group concat的使用
find_in_set
两张表A,B,其中B的id值在a的uid中,且存在多值用逗号连接
例如
A
id |
---|
1 |
2 |
3 |
B
id | uid |
---|---|
1 | 1,2,3 |
// An highlighted block
select m.id as aid,u,uid as uid from 表B名 m
left join 表A名 u on FIND_IN_SET(m.id,u.uid)
vo.aid | vo.uid |
---|---|
1 | 1 |
1 | 2 |
1 | 3 |
group_concat
两张表A,B,其中B的id值在a的uid中,且存在多值用逗号连接
例如
A
id |
---|
1 |
B
id | a | b | c |
---|---|---|---|
1 | 手机 | 1,2,3 | 1 |
2 | 电脑 | 4,5,6 | 1 |
// An highlighted block
select m.*,u.* from 表A m
left join (select c, GROUP_CONCAT(a) as xm, GROUP_CONCAT(b) as dh from 表B where xxx group by c ) u on u.c=m.id
where xxxxxx order by xxxxx
前台调用
vo.xm | vo.dh | vo c |
---|---|---|
手机 ,电脑 | 1,2,3,4,5,6 | 1 |