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();
相关推荐
2301_781571421 小时前
Golang格式化输出占位符都有什么_Golang fmt占位符教程【通俗】
jvm·数据库·python
养肥胖虎1 小时前
RAG学习笔记(3):区分数据库检索与RAG的使用场景
数据库·ai·rag
_ku_ku_2 小时前
数据库系统原理 · 数据库应用开发 · 自学总结
数据库
长谷深风1112 小时前
索引提速秘籍【个人八股】
mysql·b+树·索引·索引设计原则·存储引擎优化·索引维护成本·字段选择策略
No8g攻城狮2 小时前
【人大金仓】wsl2+ubuntu22.04安装人大金仓数据库V9
java·数据库·spring boot·非关系型数据库
山峰哥2 小时前
SQL慢查询调优实战:从全表扫描到索引覆盖的完整复盘
前端·数据库·sql·性能优化
Irene19913 小时前
在 WSL 中下载安装 MySQL,连接到 SQLyog(MySQL 安装在 WSL vs Windows 本地对比)
mysql·wsl
代码中介商3 小时前
Redis入门:5大数据类型全解析
数据库·redis·缓存
渣渣盟3 小时前
数据库设计范式详解(纯小白版)
数据库·oracle·软考·数据库工程师
夜雪闻竹5 小时前
Cursor 对话导入:解析 SQLite 里的宝藏
数据库·sqlite·ai编程