mysql concat 性能_mysql 函数 concat() concat_ws()

标签(空格分隔): mysql concat concat_ws

1.concat(字段1,字段2,......) 函数的作用:将多个字符串连成一个字符串

select concat(name,age) from user where id=10;//张三18

#####2.concat_ws(连接符,字段1,字段2,......)作用:将多个字符串用连接符连接成一个字符串

select concat_ws('_',name,age,email);//张三_18_xxx@163.com

concat_ws()字段有null的元素会被直接过滤

select concat_ws('_',name,age,email);

//张三_xxx@163.com age值为null会被直接过滤

concat()和concat_ws()函数连接字段不限制个数 但超过100以上会有性能影响

示例:厨品秀多店同名物料分组sql

Expense::leftJoin('expense_material as em','em.expenseId','=','expenses.id')

->leftJoin('material as m','em.materialId','=','m.id')

->leftJoin('categories as c','c.id','=','m.firstCategory')

->whereIn('expenses.shopId',$shopList)

->select([\DB::raw("concat_ws('_',c.name,m.name,m.specification) as keyName"),'c.name as categoryName','em.excludeTaxTotal as amount','em.materialId','m.name as materialName','m.specification'])

->get()->toArray();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值