文章目录
- 数据库查询,并且sql直接返回json格式
数据库查询,并且sql直接返回json格式
SELECTJSON_ARRAYAGG(JSON_OBJECT('groupId', g.id,'groupName', g.NAME,'groupColor', g.group_color,'num', COALESCE(c.num, 0),'type', g.type)) AS result
FROMxbd_group g
LEFT JOIN (SELECTgroup_id,COUNT(id) AS numFROMxbd_customer_1WHEREy_uid = 1GROUP BYgroup_id
) c ON g.id = c.group_id
WHEREg.y_uid IN (0, 1)
AND g.STATUS = 0
ORDER BYg.id
LIMIT 10
OFFSET 0;
返回值:
[{"num": 2,"type": 1,"groupId": 1,"groupName": "手机通讯录","groupColor": null},{"num": 31,"type": 4,"groupId": 4,"groupName": "未分组","groupColor": null}
]