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();
相关推荐
DevilSeagull14 分钟前
MySQL(2) 客户端工具和建库
开发语言·数据库·后端·mysql·服务
小李来了!19 分钟前
Navicate/plsql连接Oracle数据库教程
数据库·oracle
苍煜37 分钟前
慢SQL优化实战教学
java·数据库·sql
zhaoyong2221 小时前
MySQL 存储过程中字符集与排序规则不匹配导致查询性能下降的解决方案
jvm·数据库·python
sinat_383437361 小时前
golang如何从Python转型Go开发_golang从Python转型Go开发攻略
jvm·数据库·python
远洪1 小时前
claude code 国内安装使用
数据库·mysql
雨辰AI1 小时前
SpringBoot3 + 人大金仓 V9 微服务监控实战|Prometheus+Grafana+SkyWalking 全链路监控
数据库·后端·微服务·grafana·prometheus·skywalking
二哈赛车手1 小时前
新人笔记---ES和kibana启动问题以及一些常用的linux的错误排查方法,以及ES,数据库泄密解决方案[超详细]
java·linux·数据库·spring boot·笔记·elasticsearch
myrh pdmd1 小时前
maven导入spring框架
数据库·spring·maven
爬山算法2 小时前
MongoDB(118)如何在升级过程中进行数据备份?
数据库·mongodb·oracle