这是查询:
$sql = "select pn.id, pn.purchased_number, pn.plan, pn.ring_to_group,
count(rtg.id) as totalGroups,
concat_ws(',', group_concat(rtg.group_name), group_concat(rtg.id)) as groupList
from tbl_phone_numbers as pn
left join tbl_rings_to_groups as rtg on rtg.user_id=pn.user_id
where pn.user_id = ? and pn.status = ?";
$query = $this->db->query($sql, array($this->userId, 'Y'));
返回groupList
喜欢的结果,default,demo,1,2
但我想得到类似的结果:
default:1,demo:2
在MYSQL有什么建议吗??
您可以颠倒这两个函数的顺序,因此首先连接
group_name
和id
- 使用CONCAT()
orCONCAT_WS()
- 然后是组连接: