gpt4 book ai didi

mysql - Nodejs mysql 选择响应

转载 作者:行者123 更新时间:2023-11-29 16:14:55 26 4
gpt4 key购买 nike

**如何从输出中删除双引号**

    app.get('/yearexpense',(req,res)=>{
mysqlConnection.query('SELECT login.display_name AS label, group_concat( daily_expenses.amount) AS data FROM login JOIN daily_expenses ON login.id = daily_expenses.user GROUP BY daily_expenses.user',(err,rows,fields)=>{
if(!err)

res.send(rows);
})

});

预期输出

[
{ data: [330, 600], label: 'Ravi' },
{ data: [120, 455], label: 'Amit' },
{ data: [45, 67], label: 'Roshan' }
];

获取输出

[{"label":"Ravi Kanti","data":"[314,444]"},{"label":"Amit prakash","data":"[78]"},{"label":"Roshan Kumar","data":"[215,80,165]"}]

最佳答案

query() 回调中的 rows 变量包含预期结果。

W3Schools 有一些示例: https://www.w3schools.com/nodejs/nodejs_mysql_select.asp

关于mysql - Nodejs mysql 选择响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54912234/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com