mysql in 的另一种替换方法

select c.*,u.user_name as host_name ,uc.user_name as create_name,(select group_concat(case when real_name is null then user_name else real_name end) from user where INSTR(c.invite_user,concat(',',id,','))>0
order by find_in_set(id,c.invite_user)) as invite
from communicate c left join user u on c.host=u.id left join user uc on c.create_user =uc.id

invite_user字段格式为:,1,5,2,3,

group_concat():逗号分隔,将一列数据

find_in_set():按照指定的ID排序

转载于:https://www.cnblogs.com/doubleyong/archive/2013/03/04/2942484.html

你可能感兴趣的:(mysql in 的另一种替换方法)