PromptlyAll Prompts中文
Data Analysis

Write verifiable SQL based on table structure

First clarify the indicator caliber, and then generate SQL with annotations, boundary processing, and validation queries.

Customize this prompt

Complete prompt

You are a serious data engineer. Please write SQL according to your needs.

Analysis requirements: [questions to answer]
Database type: [PostgreSQL/MySQL/BigQuery/Snowflake/Others]
Table structure: [Table names, fields, types and relationships]
Indicator caliber: [Time, deduplication, status and other rules]

First explain the understanding of the relationship between caliber and table and the issues to be confirmed, and then output:
1. Executable SQL, using clear CTEs and comments
2. Handling of null values, duplicates, time zones and boundary dates
3. Check SQL for verifying totals, uniqueness and outliers
4. Possible performance issues and indexing or partitioning suggestions

Only use provided tables and fields, don't make up schema.

Example output

WITH paid_orders AS (...), first_orders AS (...)
SELECT DATE_TRUNC('month', first_paid_at) AS cohort_month, COUNT(*) AS first_buyers, ...

Validation: Check that each user_id has only one first purchase month and compare to the total paid orders.
USAGE GUIDE

When to use it

First clarify the indicator caliber, and then generate SQL with annotations, boundary processing, and validation queries. Use it as a structured starting point, then review the result against your original material.

How to fill the variables

questions to answer
Add concrete facts, context, and constraints. Mark unknown details instead of guessing.
PostgreSQL/MySQL/BigQuery/Snowflake/Others
Add concrete facts, context, and constraints. Mark unknown details instead of guessing.
Table names, fields, types and relationships
Add concrete facts, context, and constraints. Mark unknown details instead of guessing.
Time, deduplication, status and other rules
Add concrete facts, context, and constraints. Mark unknown details instead of guessing.

Get better results

  • Describe the audience and intended decision.
  • Include source material and hard constraints.
  • State what the model must not invent.

Before you use the output

  • Verify facts, numbers, and quotations.
  • Check that uncertainty is clearly labeled.
  • Test or review high-impact recommendations.

Editorial note: This template has been structured for practical use. Results vary by model and input; verify important outputs against primary sources.