gpt4 book ai didi

javascript - Alasql:UNION(或 UNION ALL)只给出表 1 的结果

转载 作者:行者123 更新时间:2023-11-29 21:32:08 33 4
gpt4 key购买 nike

在使用 alasql ( https://github.com/agershun/alasql ) 的 GROUP BY 查询中使用 UNION 或 UNION ALL 时,仅检索来自 table1 的结果。

运行单独的查询会输出正确的结果。

查看此 jfiddle http://jsfiddle.net/L8471bnk/116/

var data= [
{"label":"transport - car","value":800},
{"label":"airplane","value":234},
{"label":"train","value":500},
{"label":"glider","value":123},
{"label":"transport - motorbike","value":50},
{"label":"transport - bike","value":150}
];


var query1 = alasql('' +
'SELECT \'transport\' AS label, SUM(CAST([value] AS INT)) AS [value] ' +
'FROM ? ' +
'WHERE label LIKE \'%transport%\' ' +
'GROUP BY \'transport\' ' +
'',
[data]);

var query2 = alasql('' +
'SELECT label, SUM(CAST([value] AS INT)) AS [value] ' +
'FROM ? ' +
'WHERE label NOT LIKE \'%transport%\' ' +
'GROUP BY label' +
'',
[data]);

var queryUnion = alasql('' +
'SELECT \'transport\' AS label, SUM(CAST([value] AS INT)) AS [value] ' +
'FROM ? ' +
'WHERE label LIKE \'%transport%\' ' +
'GROUP BY \'transport\' ' +
'UNION ALL ' + //or UNION, same result!
'SELECT label, SUM(CAST([value] AS INT)) AS [value] ' +
'FROM ? ' +
'WHERE label NOT LIKE \'%transport%\' ' +
'GROUP BY label' +
'',
[data, data]);


$("#res").html("<br/>UNION IS WRONG (length is correct, but query2 results are missing!!!)!<br/>" + JSON.stringify(queryUnion) + " LENGTH: " + queryUnion.length);

$("#info").html("<br/>Query1 is correct:<br/>"
+ JSON.stringify(query1)
+ " LENGTH: " + query1.length
+ "<br/><br/>Query2 is correct<br/>" + JSON.stringify(query2)
+ " LENGTH: " + query2.length);

最佳答案

刚发现:好像是个bug?

参见 https://github.com/agershun/alasql/issues/485

:(((

关于javascript - Alasql:UNION(或 UNION ALL)只给出表 1 的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35894671/

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