Sql实现拆分字段到表
1.Mysql
set @sql = concat(right(replace(',a,b,c,d,e,f,g',',',''' as S union select '''),length(replace(',a,b,c,d,e,f,g',',',''' as S union select '''))-12), '''');
prepare stmt from @sql;
execute stmt;
2.MsSql
declare @s varchar(1000),@s1 varchar(1000)
set @s = '2014-12,2015-01,2015-02,2015-03,2015-05,2015-06,2015-07,2015-08,2015-09,2015-10'
set @s1= 'select S,(select count(0) from ord_order where CONVERT(varchar(7),AddTime,120) = S) C from ('+right(replace(','+@s,',',''' as S union select '''),len(replace(','+@s,',',''' as S union select '''))-12)+''''+') a'
exec(@s1);