公司项目须要,用户所属行业,数据库存的是一个用户,多个行业,行业id 用逗号隔开,那么后台重构后,须要多条数据,mysql
多谢网友的帖子指导: http://blog.csdn.net/ldl22847/article/details/47609727sql
select a.USER_ID,substring_index(substring_index(a.ATTENTION_INDUSTRY,',',b.help_topic_id+1),',',-1) industry,1,a.USER_ORDER,NOW(),NOW() from (select t.USER_ID ,t.ATTENTION_INDUSTRY ,t.USER_ORDER from lyx_oracle_ucenter.tab_uum_user_detail t where t.user_id in (select user_id from lyx_oracle_ucenter.tab_uum_users where company_id = 1) and t.ATTENTION_INDUSTRY is not null ) a join mysql.help_topic b on b.help_topic_id < (length(a.ATTENTION_INDUSTRY) - length(replace(a.ATTENTION_INDUSTRY,',',''))+1) order by a.USER_ID;
这种方法的缺点在于,咱们须要一个拥有连续数列的独立表(这里是incre_table)。而且连续数列的最大值必定要大于符合分割的值的个数。 例若有一行的mSize 有100个逗号分割的值,那么咱们的incre_table 就须要有至少100个连续行。 固然,MySQL内部也有现成的连续数列表可用。如mysql.help_topic: help_topic_id 共有504个数值,通常能知足于大部分需求了。数据库