我有以下输出表:
Quote | art0001 | art0002 | art0003 |
=====================================
100 | 4 | 1 | 5 |
99 | 0 | 10 | 1 |
98 | 12 | 5 | 19 |
97 | 1 | 0 | 6 |
96 | 0 | 1 | 0 |
... | ... | ... | ... |
好吧,我需要art000x
列的总和来扩展输出表格,以及各篇文章的总量:
=====================================
| 17 | 17 | 31 |
目前alasql
- 代码定义如下:
var sqlRequest = [
'SELECT Quote, \ ' +
'art0001, \ ' +
'art0002, \ ' +
'art0003, \ ' +
'art0004, \ ' +
'art0005, \ ' +
'art0006, \ ' +
'art0007, \ ' +
'art0008, \ ' +
'art0009, \ ' +
'art0010, \ ' +
'art0011, \ ' +
'art0012, \ ' +
'art0013, \ ' +
'art0014 \ ' +
'INTO XLSXML("Test.xls", ?) FROM ?'
];
var opts = {
headers: true
}
$scope.btnExport = function () {
alasql(sqlString[0], [opts, $scope.listOfItems]);
}
另一个问题:如何减少sql SELECT字符串?
感谢您的帮助!
答案 0 :(得分:1)
无理由添加\
获取每个art0xx
的SUM选择SUM(art0xx)
时。
总结时,获取Quote
字段没有意义 -
所以我建议你使用:
'SELECT 'SUM(art0001) as art0001, ' +
'SUM(art0002) as art0002, ' +
'SUM(art0003) as art0003, ' +
'SUM(art0004) as art0004, ' +
'SUM(art0005) as art0005, ' +
'SUM(art0006) as art0006, ' +
'SUM(art0007) as art0007, ' +
'SUM(art0008) as art0008, ' +
'SUM(art0009) as art0009, ' +
'SUM(art0010) as art0010, ' +
'SUM(art0011) as art0011, ' +
'SUM(art0012) as art0012, ' +
'SUM(art0013) as art0013, ' +
'SUM(art0014) as art0014, ' +
'INTO XLSXML("Test.xls", ?) FROM ?'