AlaSQL / alasql

AlaSQL.js - JavaScript SQL database for browser and Node.js. Handles both traditional relational tables and nested JSON data (NoSQL). Export, store, and import data from localStorage, IndexedDB, or Excel.
http://alasql.org
MIT License
7.04k stars 659 forks source link

This example in the wiki doesn't work : How to group complex JSON object by nested properties #1460

Open grojas123 opened 2 years ago

grojas123 commented 2 years ago

I am reviewing this example : https://github.com/AlaSQL/alasql/wiki/How-to-group-complex-JSON-object-by-nested-properties I ran the code on my machine (because the Fiddle link didn't work). This is the result I got (I added an extra point to check the GROUP BY). The category I got is undefined and I don't see the results of GROUP BY of the category . Pls your guide on this .

Array [ {…} ]
​
0: Object { category: undefined, points: (3) […] }
​
length: 1
​
<prototype>: Array []

This the final result ,

{
  "points": [
    {
      "crs": null,
      "type": "FeatureCollection",
      "features": [
        {
          "geometry": {
            "type": "Point",
            "coordinates": [
              -122.382626,
              47.6657641
            ]
          },
          "type": "Feature",
          "id": 18,
          "properties": {
            "event_set__all": [
              {
                "category__category": "Live",
                "title": "the Tallboys",
                "cost": "$5",
                "description": "",
                "slug": "the-tallboys"
              }
            ],
            "neighborhood__slug": "ballard",
            "venue": "Tractor Tavern",
            "neighborhood__neighborhood": "Ballard",
            "address": "5213 Ballard Ave NW, Seattle, WA 98107, USA",
            "slug": "tractor-tavern"
          }
        }
      ]
    },
    {
      "crs": null,
      "type": "FeatureCollection",
      "features": [
        {
          "geometry": {
            "type": "Point",
            "coordinates": [
              -122.382626,
              47.6657641
            ]
          },
          "type": "Feature",
          "id": 18,
          "properties": {
            "event_set__all": [
              {
                "category__category": "Live1",
                "title": "the Tallboys",
                "cost": "$5",
                "description": "",
                "slug": "the-tallboys"
              }
            ],
            "neighborhood__slug": "ballard",
            "venue": "Tractor Tavern",
            "neighborhood__neighborhood": "Ballard",
            "address": "5213 Ballard Ave NW, Seattle, WA 98107, USA",
            "slug": "tractor-tavern"
          }
        }
      ]
    },
    {
      "crs": null,
      "type": "FeatureCollection",
      "features": [
        {
          "geometry": {
            "type": "Point",
            "coordinates": [
              -122.382626,
              47.6657641
            ]
          },
          "type": "Feature",
          "id": 18,
          "properties": {
            "event_set__all": [
              {
                "category__category": "Live1",
                "title": "the Tallboys",
                "cost": "$5",
                "description": "",
                "slug": "the-tallboys"
              }
            ],
            "neighborhood__slug": "ballard",
            "venue": "Tractor Tavern",
            "neighborhood__neighborhood": "Ballard",
            "address": "5213 Ballard Ave NW, Seattle, WA 98107, USA",
            "slug": "tractor-tavern"
          }
        }
      ]
    }
  ]
}
grojas123 commented 2 years ago

Works if I use var res = alasql('SELECT features->0->properties->event_set__all->0->category__category , ARRAY(_) AS points FROM ? GROUP BY features->0->properties->event_set__all->0->category__category ',[data]); but with SELECT features->0->properties->event_set__all->0->category__category AS category dont work . Pls your guide .

mathiasrw commented 2 years ago

Any inputs here @agershun ?