How to query Javascript object using SQL when column names contain spaces?

user3313941

I want to query a javascript array object using SQL(to perform grouping on data).

var data = [{ 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 }];

var res = alasql('SELECT dep, SUM(qt) AS qt, SUM(qt*price) AS amt, AGGR(amt/qt) AS price FROM ? GROUP BY dep',[data]);



document.getElementById("res").textContent = JSON.stringify(res);

But in my original scenario, I have column names with spaces as:

 var data = [{ "dep name": 'A', qt: 10, price: 5},
     { "dep name": 'A', qt: 5,  price: 2.30 },
     { "dep name": 'B', qt: 3,  price: 2.20 },
     { "dep name": 'C', qt: 1,  price: 4 },
     { "dep name": 'C', qt: 4,  price: 10 }];

How to modify the above SQL query so that column name with spaces can be used. Any help would be greatly appreciated.

vhu

You can use backticks (`) to escape MySQL column names. This allows you to:

SELECT A as `dep name` ...

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

SQL Server: how to limit results based on query

来自分类Dev

How to check if an object is JavaScript object in Rhino

来自分类Dev

Route using underscores instead of spaces

来自分类Dev

SQL query in Foreach loop using array variable

来自分类Dev

Query for two different result sets and then filter on a column that each contain

来自分类Dev

How do I count instances of values in columns by individual column using only SQL?

来自分类Dev

How to convert a javascript object into an NSDictionary using JavaScriptCore

来自分类Dev

javascript - How to reduce extra white spaces except line breaks

来自分类Dev

JavaScript: How to make a copy of a object?

来自分类Dev

How can I return an anonymous object in Javascript?

来自分类Dev

SQL Query giving an error of Unknown Column

来自分类Dev

How can I create this complicated SQL query?

来自分类Dev

How to check if the array of object is null using react and javascript?

来自分类Dev

How do you count misspelled fields using a SQL query?

来自分类Dev

How to choose specific rows in an sql query?

来自分类Dev

How can I create a SUM of one column within a query in SQL?

来自分类Dev

How to get all key in JSON object (javascript)

来自分类Dev

advanced sql query using join

来自分类Dev

How to insert data into sql server database when the primary key column already set default identity(1, 1)

来自分类Dev

SQL query should not return rows that contain null values in pivot table

来自分类Dev

Using Javascript Variables as WP_Query Parameters

来自分类Dev

List names of all available MS SQL databases on server using python

来自分类Dev

Sum using CASE when using Len(column_name)

来自分类Dev

MySQL and PYTHON. How to query an WHERE 'column' IN tuple

来自分类Dev

Power query pivot column error on sorted data works when not sorted

来自分类Dev

How to get only value of sql query without header using groovy

来自分类Dev

How to send javascript object to php via ajax?

来自分类Dev

EF Core 2, .NET CORE 2 :How do I query the same column for multiple conditions using IQueryable<T>?

来自分类Dev

使用 column_names.include?防止SQL注入?

Related 相关文章

  1. 1

    SQL Server: how to limit results based on query

  2. 2

    How to check if an object is JavaScript object in Rhino

  3. 3

    Route using underscores instead of spaces

  4. 4

    SQL query in Foreach loop using array variable

  5. 5

    Query for two different result sets and then filter on a column that each contain

  6. 6

    How do I count instances of values in columns by individual column using only SQL?

  7. 7

    How to convert a javascript object into an NSDictionary using JavaScriptCore

  8. 8

    javascript - How to reduce extra white spaces except line breaks

  9. 9

    JavaScript: How to make a copy of a object?

  10. 10

    How can I return an anonymous object in Javascript?

  11. 11

    SQL Query giving an error of Unknown Column

  12. 12

    How can I create this complicated SQL query?

  13. 13

    How to check if the array of object is null using react and javascript?

  14. 14

    How do you count misspelled fields using a SQL query?

  15. 15

    How to choose specific rows in an sql query?

  16. 16

    How can I create a SUM of one column within a query in SQL?

  17. 17

    How to get all key in JSON object (javascript)

  18. 18

    advanced sql query using join

  19. 19

    How to insert data into sql server database when the primary key column already set default identity(1, 1)

  20. 20

    SQL query should not return rows that contain null values in pivot table

  21. 21

    Using Javascript Variables as WP_Query Parameters

  22. 22

    List names of all available MS SQL databases on server using python

  23. 23

    Sum using CASE when using Len(column_name)

  24. 24

    MySQL and PYTHON. How to query an WHERE 'column' IN tuple

  25. 25

    Power query pivot column error on sorted data works when not sorted

  26. 26

    How to get only value of sql query without header using groovy

  27. 27

    How to send javascript object to php via ajax?

  28. 28

    EF Core 2, .NET CORE 2 :How do I query the same column for multiple conditions using IQueryable<T>?

  29. 29

    使用 column_names.include?防止SQL注入?

热门标签

归档