MYSQL截取列里面的数据为多行

来源:互联网 发布:linux shell 复制粘贴 编辑:程序博客网 时间:2024/06/07 06:42




/**单选统计**/

SELECT syyou,count(syyou) from test_form_one group BY syyou

/**复选统计**/
select substring_index(substring_index(a.race,'|',b.help_topic_id+1),'|',-1) as race,count(substring_index(substring_index(a.race,'|',b.help_topic_id+1),'|',-1))
from test_form_one a
join mysql.help_topic b
on b.help_topic_id < (length(a.race) - length(replace(a.race,'|',''))+1)
group BY substring_index(substring_index(a.race,'|',b.help_topic_id+1),'|',-1)

order by a.id;


截取的核心语句为:

select substring_index(substring_index(a.race,'|',b.help_topic_id+1),'|',-1) from test_form_one a
join mysql.help_topic b
on b.help_topic_id < (length(a.race) - length(replace(a.race,'|',''))+1)
order by a.id;

参考的文件地址:http://www.cnblogs.com/cenalulu/archive/2012/08/20/2647463.html

0 0
原创粉丝点击