40.Shopper - 列出了十大最畅销的产品

Don想知道是dimestore商城十大最畅销的产品.

由于N1QL,我们现在可以轻松地查询他产生这个列表中的数据。

SELECT product.name, SUM(items.count) AS unitsSold 
FROM purchases UNNEST purchases.lineItems AS items 
JOIN product ON KEYS items.product 
GROUP BY product 
ORDER BY unitsSold DESC LIMIT 10

结果:

{
  "results": [
    {
      "name": "Pyrex Prepware 2-Cup Measuring Cup, Clear with Red Measurements",
      "unitsSold": 182
    },
    {
      "name": "Danze D304055RB Sheridan Two Handle Widespread Lavatory Faucet, Oil Rubbed Bronze",
      "unitsSold": 164
    },
    {
      "name": "Hunter Ceiling Fans 21647 Caribbean Breeze Fan - Weathered Bronze Indoor Fan 54",
      "unitsSold": 156
    },
    {
      "name": "New Super Mario Bros. 2",
      "unitsSold": 156
    },
    {
      "name": "Eagle Claw Youth Fishing Vest (Small)",
      "unitsSold": 154
    },
    {
      "name": "Aroma ARC-914SBD 4-Cup (Uncooked) 8-Cup (Cooked) Digital Rice Cooker and Food Steamer",
      "unitsSold": 152
    },
    {
      "name": "Angels' Eyes Tear-Stain Eliminator for Dogs and Cats, Beef Flavor, 120 Grams Bottle",
      "unitsSold": 151
    },
    {
      "name": "BeginAgain Eco YoYo - Green",
      "unitsSold": 150
    },
    {
      "name": "Brother Project Runway CE7070PRW 70-Stitch Computerized Sewing Machine with Wide Table",
      "unitsSold": 150
    },
    {
      "name": "Briggs & Riley 13 Inch Slim Clamshell Briefcase",
      "unitsSold": 149
    }
  ]
}

Last updated

Was this helpful?