create or replace TABLE ecommerce.products AS
SELECT
*
FROM
`data-to-insights.ecommerce.products`
注意:此副本仅供您查看,本实验中的查询将使用 data-to-insights 项目。
点击 ecommerce 数据集以显示 products 表。
通过“预览”和“架构”标签页检查数据
前往 ecommerce > products 数据集,然后点击预览标签页以查看数据。
点击架构标签页。
创建一个查询来显示情感最积极的前 5 种商品
在查询编辑器中编写 SQL 查询。
可能的解决方法:
SELECT
SKU,
name,
sentimentScore,
sentimentMagnitude
FROM
`data-to-insights.ecommerce.products`
ORDER BY
sentimentScore DESC
LIMIT 5
修改查询以显示情感最消极的前 5 种商品,并滤除 NULL 值。
可能的解决方法:
SELECT
SKU,
name,
sentimentScore,
sentimentMagnitude
FROM
`data-to-insights.ecommerce.products`
WHERE sentimentScore IS NOT NULL
ORDER BY
sentimentScore
LIMIT 5
返回总订购数量 (productQuantity). 提示:使用 SUM() with a IFNULL 条件
仅过滤 20170801 的销量
ORDER BY 将订单数量最多的 SKU 排在最前面
可能的解决方法:
# pull what sold on 08/01/2017
CREATE OR REPLACE TABLE ecommerce.sales_by_sku_20170801 AS
SELECT
productSKU,
SUM(IFNULL(productQuantity,0)) AS total_ordered
FROM
`data-to-insights.ecommerce.all_sessions_raw`
WHERE date = '20170801'
GROUP BY productSKU
ORDER BY total_ordered DESC #462 skus sold
点击 sales_by_sku 表,然后点击预览标签页。
售出了多少不同的商品 SKU?
答案:462
下面,联接两个数据集,以便用商品库存信息充实销售数据。
联接销售数据和库存数据
通过 JOIN,使用商品库存数据集中的以下字段来充实网站电子商务数据:
name
stockLevel
restockingLeadTime
sentimentScore
sentimentMagnitude
将未编写完全的查询补充完整:
# join against product inventory to get name
SELECT DISTINCT
website.productSKU,
website.total_ordered,
inventory.name,
inventory.stockLevel,
inventory.restockingLeadTime,
inventory.sentimentScore,
inventory.sentimentMagnitude
FROM
ecommerce.sales_by_sku_20170801 AS website
LEFT JOIN `data-to-insights.ecommerce.products` AS inventory
ORDER BY total_ordered DESC
可能的解决方法:
# join against product inventory to get name
SELECT DISTINCT
website.productSKU,
website.total_ordered,
inventory.name,
inventory.stockLevel,
inventory.restockingLeadTime,
inventory.sentimentScore,
inventory.sentimentMagnitude
FROM
ecommerce.sales_by_sku_20170801 AS website
LEFT JOIN `data-to-insights.ecommerce.products` AS inventory
ON website.productSKU = inventory.SKU
ORDER BY total_ordered DESC
# calculate ratio and filter
SELECT DISTINCT
website.productSKU,
website.total_ordered,
inventory.name,
inventory.stockLevel,
inventory.restockingLeadTime,
inventory.sentimentScore,
inventory.sentimentMagnitude,
SAFE_DIVIDE(website.total_ordered, inventory.stockLevel) AS ratio
FROM
ecommerce.sales_by_sku_20170801 AS website
LEFT JOIN `data-to-insights.ecommerce.products` AS inventory
ON website.productSKU = inventory.SKU
# gone through more than 50% of inventory for the month
WHERE SAFE_DIVIDE(website.total_ordered,inventory.stockLevel) >= .50
ORDER BY total_ordered DESC
…可帮助您充分利用 Google Cloud 技术。我们的课程会讲解各项技能与最佳实践,可帮助您迅速上手使用并继续学习更深入的知识。我们提供从基础到高级的全方位培训,并有点播、直播和虚拟三种方式选择,让您可以按照自己的日程安排学习时间。各项认证可以帮助您核实并证明您在 Google Cloud 技术方面的技能与专业知识。
上次更新手册的时间:2024 年 2 月 3 日
上次测试实验的时间:2023 年 10 月 31 日
版权所有 2025 Google LLC 保留所有权利。Google 和 Google 徽标是 Google LLC 的商标。其他所有公司名和产品名可能是其各自相关公司的商标。