[英]Access to Json element with ' ' name (Subquery mysql nodejs)
I'm working in a backend with NodeJS and Mysql, everything is good but recently I've faced a small details where I'm stuck since added a SUBQUERY.我正在使用 NodeJS 和 Mysql 在后端工作,一切都很好,但最近我遇到了一个小细节,自从添加了一个 SUBQUERY 之后我就被卡住了。
This is the Mysql Query:这是 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;
}
The Object array returned is ok, but the SUBQUERY Object is really weird, it returns with a empty name ( '': { credit_notes: 0 }
).返回的对象数组没问题,但 SUBQUERY 对象真的很奇怪,它返回一个空名称(
'': { credit_notes: 0 }
)。 I suppose the SUBQUERY creates a new object with a known name.我想 SUBQUERY 创建一个具有已知名称的新对象。 ¿How could access a '' json element?, how could put a name SUBQuery like:
'sub': { credit_notes: 0 }
?. ¿How can access a '' json element?,如何将名称 SUBQuery 如:
'sub': { credit_notes: 0 }
?.
Thanks.谢谢。
[ 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 } } ... ]
Just take brackets as property accessor .只需将括号作为属性访问器。
var item = { '': 'foo' }; console.log(item['']);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.