1. 程式人生 > >mysql字符串的常用函數(截取和拼接)

mysql字符串的常用函數(截取和拼接)

sele 截取 lec -c 常用 from aaa mysql cat

#截取字符串(先正序取2個,再倒序取1個)
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(‘aaa-gg-cc-dd‘,‘-‘,2),‘-‘,-1)

#獲取子表某個字段的拼接(如:goods_name;goods_name2;goods_name3)
select o1.sn,group_concat(g1.goods_name separator ‘;‘) from orders o1
left join goods_orders g1 on g1.order_id = o1.id
where o1.created > ‘2018-06-13‘ group by o1.sn

mysql字符串的常用函數(截取和拼接)