公司項目須要,用戶所屬行業,數據庫存的是一個用戶,多個行業,行業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個數值,通常能知足於大部分需求了。數據庫