JSON/q

A JSON-based data access specification

Query

{
  "group": {
    "into": "g", 
    "by": "p.category"
  }, 
  "as": "p", 
  "from": "Products", 
  "select": {
    "category": "g.key", 
    "totalUnitsInStock": "g.sum(p.unitsInStock)"
  }
}

Results

[
  {
    "category": "Beverages", 
    "totalUnitsInStock": 559
  }, 
  {
    "category": "Condiments", 
    "totalUnitsInStock": 507
  }, 
  {
    "category": "Produce", 
    "totalUnitsInStock": 100
  }, 
  {
    "category": "Meat/Poultry", 
    "totalUnitsInStock": 165
  }, 
  {
    "category": "Seafood", 
    "totalUnitsInStock": 701
  }, 
  {
    "category": "Dairy Product", 
    "totalUnitsInStock": 393
  }, 
  {
    "category": "Confections", 
    "totalUnitsInStock": 386
  }, 
  {
    "category": "Grains/Cereal", 
    "totalUnitsInStock": 308
  }
]