> For the complete documentation index, see [llms.txt](https://www.boxhero.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.boxhero.io/docs/documentation/zh/qi-ta-gong-neng/custom-analytics.md).

# 自定义分析

<figure><img src="/files/85c3d9c9351f9e6c3c5d1291856c77faa0c607fe" alt=""><figcaption></figcaption></figure>

***

## 主要亮点

* 用通俗语言提问， **AI 助手** 会为你编写 SQL。
* 使用 SQL 查询你的 BoxHero 数据。
* 结合条件（例如商品、属性、价格、日期范围、合作伙伴）来定义你想作为自定义报告返回的数据。
* 保存你经常使用的查询，并可随时重新打开。
* 将结果导出到 Excel，以便进一步分析或生成报告。

## 使用场景

标准功能 <mark style="color:$primary;">`库存报表`</mark> 可让你快速查看选定期间内的关键指标，例如平均库存数量和库存周转率。由于这些报告使用预定义的公式和字段，它们可能无法涵盖团队所需的每一种分析。

<mark style="color:$primary;">`自定义分析`</mark> 让你更灵活地探索数据，尤其适用于：

* 你在标准功能中找不到所需的数据 [库存报表](/docs/documentation/zh/qi-ta-gong-neng/analytics.md)
* 你想按商品、供应商、客户、团队成员或其他详细条件筛选或分组数据
* 你需要按时间进行分析，例如按月、按季度或同比
* 你想保存依赖的报告并再次使用
* 你需要灵活的数据来支持报告或决策

***

## 如何使用自定义分析

### 1. 开始使用

前往 <mark style="color:$primary;">`报表`</mark> > <mark style="color:$primary;">`自定义分析`</mark>. 这会打开一个新的工作区，你可以在其中创建和管理 SQL 查询。然后，选择 <mark style="color:$primary;">`+ 新建`</mark> 来创建一个新查询。

<figure><img src="/files/b76ed287a059af4187177ad224d6ac51bc523bb1" alt=""><figcaption></figcaption></figure>

### 2. 编写查询

你可以通过两种方式编写查询：

1. **使用 AI 助手** 将自然语言问题生成 SQL（推荐给大多数用户）。
2. **直接编写 SQL** 使用 [DuckDB SQL](https://duckdb.org/docs/stable/sql/introduction).

<figure><img src="/files/ecdb584dc68703a1dee49e7e00c230d7cd994e92" alt=""><figcaption></figcaption></figure>

#### 使用 AI 助手

该 <mark style="color:$primary;">`AI 助手`</mark> 可以将自然语言问题转换为可执行的 SQL 查询。使用它无需了解 SQL。&#x20;

在助手面板中输入你的问题并按回车。助手会生成 SQL，将其应用到编辑器并运行。结果会显示在查询下方。

如果你想调整任何内容，可以在保存前编辑生成的 SQL。

{% embed url="<https://customer-0jrbilsa8yt3k758.cloudflarestream.com/38e5c1fa675d1d7f16b1d9e95a6aabd4/iframe?autoplay=true&controls=false&letterboxColor=transparent&loop=true&muted=true&poster=https://customer-0jrbilsa8yt3k758.cloudflarestream.com/38e5c1fa675d1d7f16b1d9e95a6aabd4/thumbnails/thumbnail.jpg?height=1080&preload=true>" %}

**示例问题**

* 低于安全库存水平的商品
* 过去 90 天内哪些商品没有销售？
* 本月按销售数量排名前 10 的 SKU
* 已超过预计到达日期的未结采购订单
* 按地点查看库存水平&#x20;

#### 构建可复用查询

你可以让助手在查询中包含可调整的筛选条件，例如日期范围或合作伙伴名称。助手会使用查询变量，因此你之后无需重写 SQL 即可更改输入。

例如，输入 *“按商品统计销售额，日期范围可调整”* 会生成一个带日期变量的查询，每次运行时都会提示输入。

<figure><img src="/files/14e12c4e8246bf279e4e7c482c7509ca21e4d843" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
AI 助手最适合处理 **具体的** **问题**。\
不要用 *“显示销售额，”* 可以试试 *“本月收入最高的 10 个商品。”*
{% endhint %}

{% embed url="<https://customer-0jrbilsa8yt3k758.cloudflarestream.com/27509a71c500d77cd43f29409abe0d68/iframe?autoplay=true&controls=false&letterboxColor=transparent&loop=true&muted=true&poster=https://customer-0jrbilsa8yt3k758.cloudflarestream.com/27509a71c500d77cd43f29409abe0d68/thumbnails/thumbnail.jpg?height=1080&preload=true>" %}

{% hint style="success" %}
点击 <mark style="color:$primary;">`图表`</mark> 按钮可将数据可视化——支持柱状图、折线图、饼图、堆叠柱状图、堆叠面积图。
{% endhint %}

### 3. 保存查询

选择 <mark style="color:$primary;">`执行`</mark> 来测试你的查询。由于结果取决于你编写的条件，请检查输出以确认其符合预期。

如果你打算重复使用某个查询，请选择 <mark style="color:$primary;">`保存`</mark> 右上角的按钮。已保存的查询会显示在左侧边栏中，你可以随时打开并运行。

查询成功运行后，你可以使用 <mark style="color:$primary;">`导出到 Excel`</mark>.

<figure><img src="/files/24174802f4f520305f2859e01d12e6248573272b" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
你的数据会自动同步 **每天一次**。\
如需立即同步，请点击侧边栏底部的同步图标（🔄）。
{% endhint %}

***

## 查询变量

如果你在查询中包含 `{{variable_name}}` ，查询运行时会自动生成一个输入框。该输入框中填写的值会应用到 SQL 查询中的变量。

当你保存查询后，团队成员可以在变量字段中输入自己的值，并在需要时运行报告。

#### 示例

1. 要搜索包含特定关键词的商品，请输入以下查询：

```sql
select sku, name 
from items 
where name ilike '%' || {{item_name}} || '%';
```

2. 运行查询时，会显示一个名为 **item\_name** 的输入框。

<figure><img src="/files/ff10507d7dad3d8698f4bd29566c9e7f1bb1c289" alt=""><figcaption></figcaption></figure>

3. 输入一个关键词，例如 *`sweater`* ，结果将显示所有名称中包含 *“sweater”* 的商品。

<figure><img src="/files/9ad6ab46f764a3e936e853bddf61e9a0e177efd8" alt=""><figcaption></figcaption></figure>

4. 如果你打算再次使用该查询，请保存它。你可以随时从左侧菜单中选择并加载已保存的查询。

<figure><img src="/files/3f0c547daa69b81e10e23927bdfef0f3b4826352" alt=""><figcaption></figcaption></figure>

***

## 示例

自定义分析包含可立即运行的内置模板。查看某个模板以了解其工作方式，然后根据需要进行调整或基于它创建新查询。

#### 模板

* 每周库存出入报告
* 月度采购与销售趋势
* 按商品查看最近出库日期

<figure><img src="/files/dd28218fc7cb2483735640a424e79bfc6408bad0" alt=""><figcaption></figcaption></figure>

***

## 常见问题

**还有疑问吗？** 查看我们的自定义分析常见问题：

{% content-ref url="/spaces/1XHeAQmLMHSILvJsICC2/pages/f969c55dc2ca18b5d0d3b15257518ca5bfd811ea" %}
[自定义分析](/docs/faq/zh/bao-biao/zi-ding-yi-fen-xi.md)
{% endcontent-ref %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.boxhero.io/docs/documentation/zh/qi-ta-gong-neng/custom-analytics.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
