37.Shopper - 在栏目中找到最流行的一些产品

有如此多的设备可供选择,也想知道排行前三的电器,这样他可以很容易地选择购买哪一个。

评价前三的电器是什么?运行该查询,算出来。

SELECT
    product.name, 
    COUNT(reviews) AS reviewCount,
    ROUND(AVG(reviews.rating),1) AS avgRating,
    product.color
    FROM reviews
    JOIN product ON KEYS reviews.productId
    UNNEST product.categories AS category
    WHERE category = "Appliances"
    GROUP BY category, product
    ORDER BY avgRating 
    DESC LIMIT 3

结果:

{
  "results": [
    {
      "avgRating": 4.5,
      "color": "azure",
      "name": "Waring Pro IC70 Professional Stainless Steel Large-Capacity Ice Crusher",
      "reviewCount": 2
    },
    {
      "avgRating": 4,
      "color": "green",
      "name": "Air King AILT4 Lint Trap",
      "reviewCount": 6
    },
    {
      "avgRating": 3.4,
      "color": "red",
      "name": "Bosch HEZ1090 LP Conversion Kit for Bosch Free-standing Gas Ranges (300 and 500 Series)",
      "reviewCount": 5
    }
  ]
}

Last updated

Was this helpful?