大模型网摘deepseek.wang

AI Usage Guides · 2026-11-20

Let DeepSeek Write Your SQL and Interpret the Results

Data and SQL sit firmly in DeepSeek's comfort zone: strong coding ability, solid math reasoning, the V-series handles everyday queries well, and the R-series deep thinking mode fits complex multi-table joins and performance tuning. This post gives you two paste-ready prompt templates—one for writing SQL, one for interpreting results—plus a few details that keep the model on track. Deep thinking can be toggled as needed: don't enable it for simple single-table queries, it wastes time; turn it on for complex aggregations, window functions, and execution plan analysis, where the payoff is clear.

1. Writing SQL: Feed It Clear Constraints, Skip the Roleplay

A common mistake is writing a long preamble like "You are a senior DBA with twenty years of experience…". Deep thinking models don't respond to theatrics; they respond to clear inputs: schema, field types, business definitions, and the target SQL dialect. Fill in this template and paste it:

[Task] Write a SQL query that satisfies the following requirements:
1. Business question: for 2024, calculate the share of repeat purchasers
   (users with >= 2 orders) among all ordering users, per month.
2. Database: MySQL 8.0.
3. Schema:
   - orders(id INT, user_id INT, amount DECIMAL(10,2), created_at DATETIME)
   - users(id INT, name VARCHAR(50), registered_at DATETIME)
4. Constraints:
   - Count only paid orders (orders.status = 'paid')
   - Filter time by created_at, timezone UTC+8
   - Round results to two decimal places
5. Output format: SQL + a one-line comment for each key step.

Three key points: state the database and version explicitly (MySQL, PostgreSQL, and HiveSQL differ noticeably in syntax); include field types, otherwise the model may guess date formats wrong; and write business definitions (what counts as "repeat purchase", what counts as "paid") explicitly—this is where the model drifts most easily.

2. When to Enable Deep Thinking

The rule is simple: if the SQL involves nested subqueries, window functions, or CTE chains, or you need the model to analyze execution plans or compare indexing options, enable the R-series deep thinking mode. Single-table selects and group-bys? The V-series handles them directly—faster and cheaper on tokens. For frequent API calls, routing simple queries to the V-series and complex analysis to deep thinking is a common cost-saving pattern (check the official page for current pricing).

3. Interpreting Results: Paste Them Back and Let the Model Play Analyst

Running the query is only step one; the real value is in interpretation. Paste the results back into the conversation with this template:

[Context] I ran your previous SQL to find the repeat-purchase rate.
[Query results] (paste as a table or CSV)
month, total_ordering_users, repeat_users, repeat_rate
2024-01, 1200, 380, 0.32
2024-02, 1350, 355, 0.26
2024-03, 1500, 420, 0.28
[Task]
1. Interpret the trends and anomalies in this data, in Chinese.
2. Offer at least two plausible business explanations.
3. Specify what additional data would verify each hypothesis, and write the corresponding SQL.

The third step is the key: asking the model to propose "what to query next" creates a write-query → read-results → follow-up loop instead of a one-shot Q&A. Keep the pasted data small—dozens of rows at most; too many rows dilutes the focus. And mask sensitive data (phone numbers, ID numbers) before pasting, especially if you're using an online service.

4. Two Common Pitfalls

First, the model may "hallucinate" fields or functions that don't exist. Mitigation: paste the full schema, and scan field names by eye before executing; if it errors, paste the error message back verbatim and let the model fix it—usually converges within one or two rounds.

Second, definition drift. The model's understanding of business jargon may not match your team's internal definitions—for example, "active user" might mean logged-in to some, purchased to others. Add a "term definitions" section to your template spelling out each keyword; it noticeably reduces rework.

5. Going Further: A Locally Deployed Data Assistant

DeepSeek's open weights and local deployment support mean sensitive data can stay inside your network. Spin up a local service with tools like Ollama or vLLM, wire it into your own chat interface or scripts, and reuse both templates. Teams with strict data-compliance requirements should consider this route (see the official repo docs for deployment details and hardware requirements).

Save the two templates as snippets. Next time you face an unfamiliar schema or a puzzling result set, just fill in the blanks—the model's efficiency advantage on writing SQL and reading data is real; your time is better spent defining problems and validating conclusions.