2

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);
4

1 に答える 1

2

ちょうど見つけた: それはバグのようですか?

https://github.com/agershun/alasql/issues/485を参照してください

:((((

于 2016-03-09T14:43:17.990 に答える