You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
agershun edited this page Dec 28, 2014
·
3 revisions
How to use SQL to query javascript objects?
Question
Is there a way to run an SQL query against javascript objects to find data within them? Specifically I'm looking for a way to query a few objects (each representing a table of data) and perform a join on them.
Answer
Alasql is a JavaScript SQL data manipulating library and supports SQL syntax.
This is an example:
vardata=[{dep: 'A',qt: 10,price: 5},{dep: 'A',qt: 5,price: 2.30},{dep: 'B',qt: 3,price: 2.20},{dep: 'C',qt: 1,price: 4},{dep: 'C',qt: 4,price: 10}];varres=alasql('SELECT dep, SUM(qt) AS qt, SUM(qt*price) AS amt, \ FROM ? GROUP BY dep',[data]);