> ## Documentation Index
> Fetch the complete documentation index at: https://docs.devin.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 在 Slack 中进行即席数据查询

export const UseCaseHero = ({title, description, prompt, category, features, devinUrl, agent, intent, playbookId, type}) => {
  const encodedPrompt = encodeURIComponent(prompt || '');
  const tag = 'docs-use-case-gallery';
  const utm = 'utm_source=docs&utm_medium=use-case-gallery&utm_campaign=hero-cta';
  const agentParams = (agent ? '&agent=' + agent : '') + (intent ? '&intent=' + intent : '') + (playbookId ? '&playbookId=' + playbookId : '');
  const devinHref = type === 'schedule' ? 'https://app.devin.ai/settings/schedules/create?' + utm + agentParams + (prompt ? '&prompt=' + encodedPrompt : '') : type === 'review' ? 'https://app.devin.ai/review?' + utm : agent === 'ada' ? 'https://app.devin.ai/search?' + utm + '&noSubmit=true' + (prompt ? '&prompt=' + encodedPrompt : '') : devinUrl ? devinUrl.includes('?') ? devinUrl + '&' + utm + agentParams : devinUrl + '?' + utm + agentParams : prompt ? 'https://app.devin.ai/?tags=' + tag + '&' + utm + agentParams + '&prompt=' + encodedPrompt : 'https://app.devin.ai/?' + utm + agentParams;
  const buttonLabel = type === 'schedule' ? 'Schedule in Devin ↗' : type === 'review' ? 'Set Up Devin Review ↗' : agent === 'advanced' ? 'Try in Devin ↗' : agent === 'dana' ? 'Try in Dana ↗' : agent === 'ada' ? 'Try in Ask Devin ↗' : 'Try in Devin ↗';
  const featureList = features ? features.split(',').map(f => f.trim()) : [];
  return <div className="uc-hero">
      <div className="uc-hero-inner">
        <div className="uc-hero-left">
          <h1 className="uc-hero-title">{title}</h1>
          <p className="uc-hero-desc">{description}</p>
          <div>
            <a href={devinHref} target="_blank" rel="noopener noreferrer" className="try-in-devin-btn">
              {buttonLabel}
            </a>
          </div>
        </div>
        <div className="uc-hero-meta">
          <div className="uc-meta-item">
            <span className="uc-meta-label">Author</span>
            <span className="uc-meta-value">Cognition</span>
          </div>
          <div className="uc-meta-item">
            <span className="uc-meta-label">Category</span>
            <span className="uc-meta-value">{category}</span>
          </div>
          {featureList.length > 0 && <div className="uc-meta-item">
              <span className="uc-meta-label">Features</span>
              <span className="uc-meta-value">{featureList.join(', ')}</span>
            </div>}
        </div>
      </div>
    </div>;
};

export const PromptBlock = ({children, type, agent, intent, playbookId}) => {
  var utm = 'utm_source=docs&utm_medium=use-case-gallery&utm_campaign=prompt-block';
  var tag = 'docs-use-case-gallery';
  var agentParams = (agent ? '&agent=' + agent : '') + (intent ? '&intent=' + intent : '') + (playbookId ? '&playbookId=' + playbookId : '');
  var label = type === 'schedule' ? 'Schedule in Devin' : type === 'playbook' ? 'Create Playbook' : type === 'knowledge' ? 'Add to Knowledge' : agent === 'advanced' ? 'Try in Devin' : agent === 'dana' ? 'Try in Dana' : agent === 'ada' ? 'Try in Ask Devin' : 'Try in Devin';
  var buildUrl = function (text) {
    var encoded = encodeURIComponent(text);
    if (type === 'schedule') return 'https://app.devin.ai/settings/schedules/create?' + utm + agentParams + '&prompt=' + encoded;
    if (type === 'playbook') return 'https://app.devin.ai/settings/playbooks/create?' + utm + '&body=' + encoded;
    if (type === 'knowledge') return 'https://app.devin.ai/knowledge?' + utm + '&body=' + encoded;
    if (agent === 'ada') return 'https://app.devin.ai/search?' + utm + '&noSubmit=true&prompt=' + encoded;
    return 'https://app.devin.ai/?tags=' + tag + '&' + utm + agentParams + '&prompt=' + encoded;
  };
  const ref = React.useRef(null);
  const [href, setHref] = React.useState('#');
  React.useEffect(() => {
    if (!ref.current) return;
    var codeEl = ref.current.querySelector('pre code');
    if (codeEl) {
      var text = codeEl.textContent.trim();
      if (text) setHref(buildUrl(text));
    }
    var header = ref.current.querySelector('[data-component-part="code-block-header"]');
    if (header && !header.querySelector('.prompt-block-devin-link')) {
      var link = document.createElement('a');
      link.href = href;
      link.target = '_blank';
      link.rel = 'noopener noreferrer';
      link.className = 'prompt-block-devin-link';
      link.style.cssText = 'display:inline-flex;align-items:center;gap:6px;text-decoration:none;color:#fff;font-size:11px;font-weight:500;padding:4px 10px;border-radius:6px;white-space:nowrap;background:#317CFF;transition:background 0.2s;margin-left:8px;';
      link.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg> ' + label;
      link.onmouseenter = function () {
        link.style.background = '#2968D9';
      };
      link.onmouseleave = function () {
        link.style.background = '#317CFF';
      };
      header.appendChild(link);
    }
    var existingLink = ref.current.querySelector('.prompt-block-devin-link');
    if (existingLink && href !== '#') existingLink.href = href;
  });
  return <div className="prompt-block" ref={ref}>{children}</div>;
};

<UseCaseHero title="在 Slack 中进行即席数据查询" description="在任意 Slack 频道中输入 /dana，使用自然英文查询你的数据库。" prompt="/dana 我们按获客渠道细分的逐周注册量增长是多少？" category="数据与分析" features="集成, MCP" agent="dana" />

<div className="uc-detail-wrapper">
  <Tip>不想手动设置？把此页面的链接粘贴到 Devin 会话中，然后让它为你完成所有设置。</Tip>

  <Steps>
    <Step title="在 MCP Marketplace 中连接数据库">
      Dana 至少需要连接一个数据库才能回答问题。前往 **Settings > [MCP Marketplace](/zh/work-with-devin/mcp)** 并启用一个数据库 MCP：

      | 数据源             | MCP 名称     | 你需要准备的内容                             |
      | --------------- | ---------- | ------------------------------------ |
      | Amazon Redshift | Redshift   | Host、port、database、username、password |
      | Google BigQuery | BigQuery   | OAuth (一键) 或 service account JSON    |
      | PostgreSQL      | PostgreSQL | Connection string                    |
      | MySQL           | MySQL      | Connection string                    |
      | Snowflake       | Snowflake  | Account、username、password            |

      点击 MCP 卡片上的 **Enable**，填写你的凭据，然后点击 **Test listing tools** 以确认连接可用。你可以连接多个数据库——Dana 会根据你的问题选择查询最相关的数据库。
    </Step>

    <Step title="使用 /dana 提出你的第一个问题">
      [Dana](/zh/work-with-devin/data-analyst) 是 Devin 的数据分析师模式——一个专门用于查询数据库、构建图表，并用自然英语回答业务问题的专业智能代理，其工具和提示都针对这些场景进行了优化。

      打开任意一个已[安装 Devin](/zh/integrations/slack) 的 Slack 频道，输入 `/dana`，然后跟上一句自然英语问题。如果你的工作区中没有 `/dana` 斜杠命令，也可以使用 `@Devin !dana ...`——两种方式完全等效。Dana 会创建一个会话，编写 SQL、执行查询，并在线程中回复。

      <PromptBlock agent="dana">
        ```txt Ask Dana a question theme={null}
        /dana What were our top 10 customers by revenue last quarter?
        ```
      </PromptBlock>

      你也可以通过提及 Devin 并使用 `!dana` 宏来调用 Dana：

      <PromptBlock agent="dana">
        ```txt Use the !dana macro theme={null}
        @Devin !dana How many active users do we have per plan tier this month?
        ```
      </PromptBlock>

      Dana 会直接在 Slack 线程中回复格式化的表格、计数，以及——在有帮助时——对结果的简要解读。无需切换到 BI 工具。

      Dana 不仅限于快速查询——它也非常擅长生成综合报告和进行深入分析。让它调查趋势、细分数据，并在多次查询中综合结论：

      <PromptBlock agent="dana">
        ```txt Deep analysis theme={null}
        /dana Conduct a deep investigation on our user growth over the past
        month. Which user segments and use cases can the growth be attributed
        to? Is it more growth in existing accounts (expansion) or top of
        funnel (new signups)? Break it down by acquisition channel and plan
        tier, and highlight any notable changes compared to the prior month.
        ```
      </PromptBlock>
    </Step>

    <Step title="向 Dana 讲解你的 schema 和业务约定">
      Dana 开箱即用，但在了解你的 schema 和业务定义后效果会显著提升。与其手动添加 Knowledge 条目，不如直接在 Slack 或 Web 应用中给 Dana 反馈，并让它把这些内容记住以便下次使用：

      * *“记住：‘active user’ 指的是过去 30 天内在 `analytics.events` 中至少有一个事件的用户。”*
      * *“我们所有的时间戳都以 UTC 存储。展示时一律转换为 America/New\_York 时区。”*
      * *“`billing.subscriptions.mrr` 的单位是美分，而不是美元。展示营收时要除以 100。”*
      * *“更新你的 Knowledge：`plan` 列的取值是 free、pro 和 enterprise——不是 basic/premium。”*

      Dana 可以列出并更新自己的 Knowledge，因此更正会随着时间累积。你提供的反馈越多——列含义、枚举值、时区规则、业务定义——Dana 在后续查询中需要追问的问题就越少。
    </Step>

    <Step title="在同一线程中继续追问">
      Dana 会在一个 Slack 线程内保持上下文，因此追问时可以引用之前的结果，而无需重复描述。

      <PromptBlock agent="dana">
        ```txt Follow up on results theme={null}
        Break that down by plan tier and show the month-over-month trend.
        ```
      </PromptBlock>

      <PromptBlock agent="dana">
        ```txt Request a visualization theme={null}
        Can you chart daily signups for the past 90 days with a 7-day moving average?
        ```
      </PromptBlock>

      对于你经常提出的问题，可以考虑创建一个包含精确查询和期望格式的[作业手册 (playbook) ](/zh/product-guides/creating-playbooks)，然后在 Slack 中通过自定义 `!macro` 触发它。
    </Step>
  </Steps>
</div>
