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();