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();
相关推荐
计算机安禾2 小时前
【数据库系统原理】第19篇:计算机存储层次结构与数据库文件的物理组织
数据库·oracle
JAVA面经实录9173 小时前
操作系统面试题
java·服务器·数据库·计算机网络·面试
摇滚侠3 小时前
mariadb-libs 被 mysql-community-libs-5.7.28-1.el7.x86_64 取代
数据库·mysql·mariadb
DIY源码阁3 小时前
JavaSwing饮品管理系统 - MySQL版
java·数据库·mysql·eclipse
专注搞钱3 小时前
GPT-4o写设备Recipe:从3小时到10分钟
数据库·人工智能·gpt·半导体
东风破1374 小时前
达梦数据库实战:备份恢复与数据迁移全攻略(实例初始化、服务注册、路径迁移)
数据库·chrome
SelectDB技术团队5 小时前
2026 SelectDB AI 产品发布会:Agent Native 数据基础设施能力全景发布
数据库·人工智能·agent·apache doris·selectdb
爱吃羊的老虎5 小时前
【数据库】模块一:数据库基础与关系代数
数据库
dishugj5 小时前
iSCSI + Multipath + ASM:Oracle RAC 共享存储技术链详解
数据库·oracle
yoothey6 小时前
MySQL事务机制解析 - 面试高分知识点
数据库·mysql·面试