gpt4 book ai didi

javascript - 如何对 alasql (AngularJS) 中的列求和

转载 作者:行者123 更新时间:2023-11-27 22:56:39 25 4
gpt4 key购买 nike

我有以下输出表:

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 字符串?

感谢您的帮助!

最佳答案

  • 没有理由添加您的 \

  • 获取每个 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 ?'

关于javascript - 如何对 alasql (AngularJS) 中的列求和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37540499/

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