gpt4 book ai didi

javascript - 访问名称为 ' ' 的 Json 元素(子查询 mysql nodejs)

转载 作者:行者123 更新时间:2023-11-29 07:25:03 25 4
gpt4 key购买 nike

我在使用 NodeJS 和 Mysql 的后端工作,一切都很好,但最近我遇到了一个小细节,自从添加了一个 SUBQUERY 后我就卡住了。

这是 Mysql 查询:

var GetHistoryPayments = function(code){
var query = "SELECT DISTINCT students.student_code, " +
"acc.id, " +
"acc.StudentCode, " +
"acc.DocumentDate1, " +
"acc.DocEntry, " +
"acc.DocumentNumber1, " +
"acc.DocTotal1, " +
"acc.GrosProfit, " +
"acc.SumApplied, " +
"acc.DocumentDate2, " +
"acc.DocumentNumber2, " +
"acc.DiffDocTotalPaidToDate as total_pay, " +
"acc.LicTradNum, " +
"acc.created_at, " +
"acc.updated_at, " +
"(SELECT COUNT(*) FROM sap_accounting_state aa WHERE aa.DocumentNumber1 = acc.DocumentNumber1 and aa.tipo like 'Nota%' and aa.SumApplied > 0 ) as credit_notes " +
"FROM sap_accounting_state_students students INNER JOIN sap_accounting_state acc ON students.student_code = acc.StudentCode " +
"WHERE acc.DiffDocTotalPaidToDate = 0 " +
"and acc.Orden = 1 " +
"and acc.DocumentDate1 > '2018-06-01' " +
"and acc.StudentCode = '" + code + "' " +

"GROUP BY acc.DocumentNumber1 " +

"ORDER BY acc.DocumentDate1 desc";
return query;
}

返回的对象数组没问题,但是SUBQUERY对象真的很奇怪,它返回的是一个空名称('': { credit_notes: 0 })。我想 SUBQUERY 创建了一个具有已知名称的新对象。 ¿如何访问“” json 元素?如何放置名称 SUBQuery,如:'sub': { credit_notes: 0 }?。

谢谢。

[ RowDataPacket {
students: { student_code: '18018' },
acc:
{ id: 3836,
StudentCode: '18018',
DocumentDate1: 2019-01-01T05:00:00.000Z,
DocEntry: 74998,
DocumentNumber1: 10042438,
DocTotal1: 1839017,
GrosProfit: 1839017,
SumApplied: 0,
DocumentDate2: null,
DocumentNumber2: 0,
total_pay: 0,
LicTradNum: '79593354',
created_at: 2019-01-18T19:48:23.000Z,
updated_at: 2019-01-18T19:48:23.000Z },
'': { credit_notes: 0 } },
RowDataPacket {
students: { student_code: '18018' },
acc:
{ id: 3842,
StudentCode: '18018',
DocumentDate1: 2018-12-06T05:00:00.000Z,
DocEntry: 72048,
DocumentNumber1: 10039576,
DocTotal1: 346500,
GrosProfit: 346500,
SumApplied: 0,
DocumentDate2: null,
DocumentNumber2: 0,
total_pay: 0,
LicTradNum: '79593354',
created_at: 2019-01-18T19:48:23.000Z,
updated_at: 2019-01-18T19:48:23.000Z },
'': { credit_notes: 1 } } ... ]

最佳答案

就把括号当成property accessor .

var item = { '': 'foo' };

console.log(item['']);

关于javascript - 访问名称为 ' ' 的 Json 元素(子查询 mysql nodejs),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54292319/

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