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();
相关推荐
卧室小白几秒前
Redis-哨兵模式
数据库·redis·缓存
GottdesKrieges4 分钟前
OceanBase恢复常见问题
java·数据库·oceanbase
卧室小白26 分钟前
redis-配置
数据库·redis·缓存
向風而行1 小时前
MySQL详解
数据库·mysql
belldeep2 小时前
本草纲目:如何应用 PostgreSQL 实现【中医药】主题数据库 ?
数据库·postgresql·本草纲目
Bert.Cai2 小时前
MySQL CURTIME()函数详解
数据库·mysql
Bert.Cai2 小时前
MySQL CURDATE()函数详解
数据库·mysql
NGSI vimp2 小时前
MySQL|MySQL 中 `DATE_FORMAT()` 函数的使用
数据库·mysql
秋92 小时前
MySQL8.0.46 与 MySQL8.4.9:跨越代际的深度差异解析与升级全指南
mysql
HAWK eoni2 小时前
Mysql 驱动程序
数据库·mysql