mysql中find_in_set结合GROUP_CONCAT使用

SELECT stationid from sys_workstation where FIND_IN_SET(stationid,(SELECT GROUP_CONCAT(opera_area) from rl_user_role where userno = 24));

注明:1.select opera_area from rl_user_role where userno = 24; 数据库查出来的数据如下图:

2.使用GROUP_CONCAT函数,  SELECT GROUP_CONCAT(opera_area) from rl_user_role where userno = 24; 查出来的数据格式如下图:

3.最后使用find_in_set,看stationid 在一个字符串(‘3,15,13’)当中没。相当与where stationid in (3,15,13)

 

注意:GROUP_CONCAT函数有长度限制,如果拼接的数据太多就丢失数据了

 

posted on 2016-07-19 11:31  17710404529  阅读(689)  评论(0编辑  收藏  举报