大家好, 请问: 使用mysql2 连接数据库时,怎么让联表查询返回结构化,层级嵌套的数据呢?
const sql = 'SELECT * FROM t_teacher LEFT JOIN t_student ON t_teacher.id = t_student.teacher_id';
mysql2.query(sql, () => {
});
// 希望返回的数据结构
const result = [
{
name: '张老师',
students: [
{
name: '小明',
},
],
},
];