mysql group_concat and laravel group_concat使用

1.说明

group_concat 只能当做字段使用

需要操作多个字段时 需要使用连接符函数 concat 或者concat_ws

sql 复制代码
select 
    a.id,a.type, a.time,a.total,a.amount,a.number,a.examine,
    b.time as btime,b.info,
    GROUP_CONCAT(DISTINCT concat(a.id,':',b.time,':',b.info) SEPARATOR '|') 
from 
    sells as a 
left join 
    records as b 
on a.id=b.form where b.type='sell';

laravel中使用

php 复制代码
$cus_voucher = DB::table('cus_voucher')
        ->where('cus_id',$id)
        ->groupBy('vid')
        ->select('vid','valid_period','vname',DB::raw('group_concat(sname,"|",times) as sometitle'))
        ->get();
相关推荐
技术宝哥3 小时前
Redis(2):Redis + Lua为什么可以实现原子性
数据库·redis·lua
学地理的小胖砸4 小时前
【Python 操作 MySQL 数据库】
数据库·python·mysql
dddaidai1234 小时前
Redis解析
数据库·redis·缓存
数据库幼崽4 小时前
MySQL 8.0 OCP 1Z0-908 121-130题
数据库·mysql·ocp
Amctwd5 小时前
【SQL】如何在 SQL 中统计结构化字符串的特征频率
数据库·sql
betazhou5 小时前
基于Linux环境实现Oracle goldengate远程抽取MySQL同步数据到MySQL
linux·数据库·mysql·oracle·ogg
lyrhhhhhhhh6 小时前
Spring 框架 JDBC 模板技术详解
java·数据库·spring
喝醉的小喵7 小时前
【mysql】并发 Insert 的死锁问题 第二弹
数据库·后端·mysql·死锁
付出不多8 小时前
Linux——mysql主从复制与读写分离
数据库·mysql
初次见面我叫泰隆8 小时前
MySQL——1、数据库基础
数据库·adb