用 Claude Code 为零售 EC 编写 BigQuery 分析 SQL
面向零售 EC 的 BigQuery 分析流程,覆盖销售、退货、广告费、毛利与人工审核。
零售 EC 团队常把销售 CSV、退货 CSV、广告费 CSV、商品成本和库存放在不同后台。周会开始时,负责人先复制粘贴,而不是判断商品页面、广告预算和补货。
本文把 BigQuery 分析拆成一个小而可审核的流程。Claude Code 负责 SQL 草稿、JOIN 键检查和审核表。人来确认成本、退货原因、广告归因、个人信息和预算判断。
本文要点
- The workflow starts from retail EC screens, not from a generic SQL tutorial.
- Sales, returns, ad cost, margin, and stock need one review table.
- Claude Code drafts SQL and review notes; humans confirm cost, privacy, campaigns, and budget decisions.
- The main CTA is 研修・相談 because BigQuery, permissions, and data boundaries are company-specific.
- Measure ROI with ad cost, return rate, product page CVR, stockouts, and weekly analysis time.
失败场景
官方资料用于确认 CSV 导入、聚合函数、GoogleSQL 函数和 IAM 资源访问。 Use BigQuery CSV loading, BigQuery aggregate functions, BigQuery functions, BigQuery IAM resource access as anchors. The documentation explains the platform, but the store must decide product IDs, return reasons, cost columns, and who can read each table.
The common failure is ranking products by revenue alone. A high-revenue SKU can have many size-related returns, high ad cost, low margin, or stockout risk. The decision needs a table that shows the trade-off.
写 SQL 前的流程
Start with the screen or CSV the team already has: orders, returns, ad cost, product master, cost, and stock. Write the column names before writing SQL. Remove customer names, addresses, phone numbers, emails, and free-text order notes.
Create a small BigQuery review memo. It should contain the dataset name, table names, join keys, date range, metrics, privacy rule, reviewer, and CTA. That memo is easier to review than a long chat transcript.
Claude Code 范围与人工审核
Claude Code can draft JOIN logic, aggregate SQL, missing-field questions, and a review checklist. It can also explain why return_rate or profit_after_ad should be visible before changing advertising spend.
Humans review product cost, return reason taxonomy, ad campaign mapping, private data, and final budget decisions. If a table includes customer-level data, stop and create a safer aggregate table first.
三个 Use case
Use case 1: 带毛利的热销商品排行
- Input: orders table, product master, cost table, stock table.
- Output: revenue, order count, gross profit, margin rate, stock warning.
- Human review: product cost, seasonal campaign, stock count, bundle pricing.
Use case 2: 把退货原因连接到商品页修改
- Input: returns table, product page URL, size guide, reviews, support notes.
- Output: return rate, reason category, page fix list, FAQ draft.
- Human review: reason classification, refund policy, warranty wording, page promise.
Use case 3: 扣除广告费后的利润
- Input: ad cost table, orders table, product master, campaign ID, date range.
- Output: ad cost, revenue, gross profit, profit after ad, budget review note.
- Human review: campaign purpose, attribution, seasonality, stop-or-continue decision.
可复制提示词
Act as a BigQuery reviewer for a retail EC store.
Goal: create one analysis memo for sales, returns, ad cost, margin, and stock.
Inputs: table names, column names, join keys, date range, privacy rule, reviewer.
Outputs: table list, SQL draft, missing questions, human review checklist, next action.
Rules: do not include customer names, addresses, phone numbers, emails, or order notes.
第一步只写列名,例如 product_id、date、order_id、revenue、return_reason、ad_cost 和 cost。不要把顾客姓名、地址、电话、邮箱或订单备注放进提示词。这个边界能让分析继续,同时减少风险。
可运行检查代码
const analysisPlan = {
dataset: "ec_analytics",
salesTable: "orders_daily",
returnTable: "returns_daily",
adTable: "ad_cost_daily",
joinKeys: ["product_id", "date"],
outputMetrics: ["revenue", "gross_profit", "return_rate", "ad_cost", "profit_after_ad"],
privacyRule: "exclude customer name, address, phone, and email",
reviewer: "EC owner checks cost, return reason, and campaign mapping",
cta: "/training/"
};
const required = [
"dataset",
"salesTable",
"returnTable",
"adTable",
"joinKeys",
"outputMetrics",
"privacyRule",
"reviewer",
"cta"
];
const missing = required.filter((key) => !analysisPlan[key]);
if (missing.length > 0) {
throw new Error("Missing BigQuery analysis fields: " + missing.join(", "));
}
if (!analysisPlan.outputMetrics.includes("profit_after_ad")) {
throw new Error("Profit after ad cost must be visible before budget decisions.");
}
if (!analysisPlan.cta.startsWith("/")) {
throw new Error("CTA must be an internal path.");
}
console.log("Retail EC BigQuery analysis plan is ready for human review.");
The code checks whether the analysis memo has the minimum fields. In a real repository, the same check can read JSON, Markdown, SQL files, or MDX frontmatter before publishing an article or running a query.
Pitfall: 只看销售额
Cause: the team cleans only the orders table. Fix: add returns and ad cost at the same product and date grain. Cause: return reasons stay as free text. Fix: create a small reason taxonomy and have a person review it.
Cause: private data enters the analysis prompt. Fix: use product-level, date-level, and campaign-level data first. If customer-level rows are required, create a separate approved process.
常见问题
Q. Can this start in a spreadsheet?
A. Yes. Start by aligning product_id and date across sales, returns, and ad cost. Move to BigQuery when the same work repeats every week.
Q. Should Claude Code decide which ads to stop?
A. No. It can show profit_after_ad and missing fields. The EC owner decides after checking stock, campaign purpose, and seasonality.
Q. Where should the conversion path go?
A. For cloud data workflows, point readers to 研修・相談. The reader often needs help with data boundaries and review flow, not only a downloadable template.
咨询路径
The business path is training or consultation. A store with revenue, returns, ads, and stock in separate tools needs a safe workflow, not only a SQL snippet. Use the article to show the first step, then invite readers to review their own tables.
实际验证结果
I verified the slug, frontmatter, internal CTA, external BigQuery references, executable JavaScript, code fence, FAQ, pitfall section, and human review path. The next action is to list safe column names and check the JOIN keys before writing production SQL.
相关文章
零售小店用 Claude Code 批量生成 POP、传单文案和陈列备注的实操步骤
面向零售店店长和导购。用 Claude Code 给 POP、传单文案、陈列备注提速,附可复制的提示词模板和一段校验脚本。
用Claude Code构建电商商店:Next.js、Stripe Checkout与库存管理
用Claude Code实现电商核心流程:商品、购物车、库存、Stripe Checkout、Webhook、后台、SEO、数据分析与售后。
Claude Code 团队使用成本看不清时,先建预算日志
记录谁在什么工作中使用 Claude Code,以及产生了什么结果,适合团队导入前一周试跑。
免费 PDF: Claude Code 速查表
输入邮箱即可获取一页 PDF,整理常用命令、审查习惯和安全工作流。
我们会妥善保护你的信息,不发送垃圾邮件。
让 Claude Code 真正进入可验证的工作流
先用免费 PDF 固定基础,再用 Gumroad 教材复用工作流;如果涉及团队导入、权限或收入路径,可以直接咨询。
关于作者
Masa
专注 Claude Code 实务流程、团队导入和内容转化的工程师。