【发布时间】:2019-08-20 03:26:46
【问题描述】:
我有一个包含多行的表格,每行都有空单元格,我正在尝试将每行中的所有空单元格计数为总数。
table schema id , name, colmn1 , colmn2, colmn3, colmn4, etc.... 直到 colmn20
我试过做这样的事情
knexDb('users').where(function() {
this.where('colmn1', '=', '')
.orWhere('colmn2', '=', '')
.orWhere('colmn3', '=', '')
.orWhere('colmn4', '=', '')
.orWhere('colmn5', '=', '')
.orWhere('colmn6', '=', '')
.orWhere('colmn7', '=', '')
.orWhere(........ etc till colmn20
})
.map(function(row) {
// console.log(row)
var emptycolmns = 0;
if(row.colmn1 === ''){
emptycolmns++
}else if (row.colmn2 === ''){
emptycolmns++
}else if ....... etc till colmn20
})
.then(rows => {
console.log(rows);
console.log(emptycolmns);
})
但这对我不起作用。
附言。如您所见,对所有列进行硬编码并不好,是否有更好的方法来实现这两种结果,并提供更好的解决方案。
【问题讨论】:
标签: knex.js