mysql获取所有父类节点

39 阅读1分钟

// router.put("/", async (req, res) => { // const {dept_id} = req.body // // delete req.body.update_time // // delete req.body.create_time // const sql = WITH RECURSIVE category_tree AS ( // SELECT dept_id, parent_id // FROM sys_dept // WHERE dept_id = ${dept_id} // UNION ALL // SELECT c.dept_id, c.parent_id // FROM sys_dept c // JOIN category_tree at ON at.parent_id = c.dept_id) // SELECT * FROM category_tree // const sql1 = update sys_dept set ? where dept_id = ${dept_id} // try { // const result = await db.query(sql) // await db.query(sql1, { // ...req.body, // ancestors:${result.map(item=>item.parentId)} // }) // res.send({ code: 200, msg: '操作成功' }) // } catch (error) { // res.send(error) // } // })