Can I execute complex SQL-style queries using javascript for json data?

I ran into a problem when I need to manipulate the json result so that I can manipulate it using sql command commands.

as left associations, and the sum and group are

So, have any of you come across this recently?

I am currently using / researching jsonsql javascript .. for now enter image description here

attach is a json file that I need to manipulate.

The new result should be like this:

enter image description here

so I assume that I needed to use left joins to be the result of such a conclusion.

My problem is to collect all / some parts from the rows and make it a column, then put it all together something like that.

Hope I make sense. Thanks for all your answer.

+4
1

, SQL JS:

var data=[{"firstName":"Alice", "age":"16"},{"firstName":"Bob", "age":"18"} ... {"firstName":"Zacharias", "age":"37"}]

SELECT * FROM json WHERE age>16, - JS:

data.filter(function(x){ return x.age>16 })

SELECT count(*) FROM json,

data.length;

SELECT avg(age) FROM json,

data.reduce(function(o,n){ return o+(n.age/data.length) }, 0)

SELECT sum(age) from json,

data.reduce(function(o,n){ return o+n.age*1 },0) 

, ?

: , . ? , JS-, , .

Edit2: reduce . :

var aaData=[{"country":"USA", "month":"1", "earnings":"1000"}, {"country":"USA", "month":"2", "earnings":"1001"},     {"country":"USA", "month":"3", "earnings":"1002"}, {"country":"Germany", "month":"1", "earnings":"1000"},     {"country":"Germany", "month":"2", "earnings":"1001"}, {"country":"Germany", "month":"3", "earnings":"1002"}]

var result=aaData.reduce(function(o, n){
    if (!o.hasOwnProperty(n.country)) o[n.country]={};
    o[n.country][n.month]=n.earnings;
    return o;
}, {})

JSFiddle.

+3

Source: https://habr.com/ru/post/1536979/


All Articles