-
Notifications
You must be signed in to change notification settings - Fork 664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Aggregate MEDIAN, STDEV not work with ROLLUP #816
Comments
Thank you for taking the time to let us know :) |
You need to rewrite this to:
```
SELECT MEDIAN([value]) from ? GROUP BY ROLLUP([column])
```
2017-02-05 16:04 GMT+03:00 Mathias Rangel Wulff <notifications@github.com>:
… Thank you for taking the time to let us know :)
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#816 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAnP4B_X6_f8orr4M0lC0NWl8G3nJ686ks5rZcjngaJpZM4L2RQG>
.
|
Thanks for your answer. both methods share the same error message, see below. var ancestors = 'SELECT DEX,MEDIAN(IND1) FROM ? GROUP BY ROLLUP(DEX)'; alasql.promise(ancestors,[data]) Error: s.sort is not a function |
Hi, |
Please find correct MEDIAN aggregate that works with ROLLUP alasql.aggr.MEDIAN = function(v,s,stage){
if(stage == 1) {
return [v];
} else if(stage ==2) {
s.push(v);
return s;
} else {
if(!s.length) {
return s;
} else {
var r = s.sort();
var p = (r.length+1)/2;
if(Number.isInteger(p)) {
return r[p-1];
} else {
return (r[Math.floor(p-1)] + r[Math.ceil(p-1)])/2;
}
}
};
}; |
Awesome! I can see you are counting the null values too - any inputs on why its better than not counting them? Code optimized slightly and committed to development branch for next release |
nulls shall not be counted alasql.aggr.MEDIAN = function(v,s,stage){
if(stage == 2) {
if(v === null) {
return s;
} else {
s.push(v);
return s;
}
} else if(stage == 1) {
if(v === null) {
return [];
} else {
return [v];
}
} else {
if(!s.length) {
return s;
} else {
var r = s.sort();
var p = (r.length+1)/2;
if(Number.isInteger(p)) {
return r[p-1];
} else {
return (r[Math.floor(p-1)] + r[Math.ceil(p-1)])/2;
}
}
};
}; |
error s.sort is not a function
SELECT MEDIAN(value) from ? GROUP BY ROLLUP(column)
The text was updated successfully, but these errors were encountered: