Files
nexus/wiki/concepts/SQL-View.md
2026-04-18 12:03:16 +08:00

921 B
Raw Blame History

title, type, tags
title type tags
SQL View concept
数据库
SQL
数据预处理

Definition

预处理的数据库视图View通过 SQL 查询定义,用于解析 JSON 字段、计算派生指标、聚合数据,使 BI 工具能直接使用数值字段。

Common Use Cases

  • 解析 JSON 字段:如 JSON_EXTRACT(prodct_rating, '$.rating') AS rating
  • 计算派生指标:如 (final_price * sold) AS total_gmv
  • 数据聚合:如按类目汇总销量、销售额

Example

CREATE OR REPLACE VIEW view_products_cleaned AS
SELECT
    id,
    title,
    category,
    final_price,
    sold,
    JSON_EXTRACT(prodct_rating, '$.rating') AS rating,
    JSON_EXTRACT(prodct_rating, '$.count') AS rating_count,
    (final_price * sold) AS total_gmv
FROM products;