sql - Conditional summing (Alasql) -


i've discovered alasql, saving me tons of work data manipulation.

now i'm trying aggregate yearly revenues each customer. i've tried partition no success, , i've tried conditional approach, returns either 2013 or 2014 data, not both @ same time:

    var custtable = alasql('select customer customer,  sum(revenue::number) revenuetotal, sum(case when year = "2013"  revenue::number end) revenue2013,  sum(case when year = "2014"  revenue::number end) revenue2014   ? group customer',  [revenuetestdata]); 

basically i'm trying this:

{"year":"2013","month":"1","customer":"some customer","revenue":"7533.36"}, {"year":"2014","month":"1","customer":"some customer","revenue":"10000"}

to this:

{"customer":"some customer","revenuetotal":"17533.36","revenue2013":7533.36","revenue2014":"10000"}

why query return 2013 or 2014, not both? right way conditionally sum?

(btw, couldn't create new tag alasql, think come handy in near future - can create it?)

try this:

sum(case when year = "2013" revenue::number else 0 end) revenue2013,   sum(case when year = "2014" revenue::number else 0 end) revenue2014  

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -