sql-queries

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

SQL Query Generator

SQL 查询生成器

Purpose

用途

Transform natural language requirements into optimized SQL queries across multiple database platforms. This skill helps product managers, analysts, and engineers generate accurate queries without manual syntax work.
将自然语言需求转化为适用于多平台数据库的优化SQL查询语句。该技能可帮助产品经理、分析师和工程师无需手动处理语法即可生成准确的查询语句。

How It Works

工作原理

Step 1: Understand Your Database Schema

步骤1:了解您的数据库架构

  • If you provide a schema file (SQL, documentation, or diagram description), I will read and analyze it
  • Extract table names, column definitions, data types, and relationships
  • Identify primary keys, foreign keys, and indexing strategies
  • 如果您提供架构文件(SQL文件、文档或图表描述),我会读取并进行分析
  • 提取表名、列定义、数据类型及表间关系
  • 识别主键、外键和索引策略

Step 2: Process Your Request

步骤2:处理您的请求

  • Clarify the exact data you need to retrieve or analyze
  • Confirm the SQL dialect (BigQuery, PostgreSQL, MySQL, Snowflake, etc.)
  • Ask for any additional requirements (filters, aggregations, sorting)
  • 明确您需要检索或分析的具体数据
  • 确认SQL方言(BigQuery、PostgreSQL、MySQL、Snowflake等)
  • 询问任何额外需求(筛选条件、聚合操作、排序规则)

Step 3: Generate Optimized Query

步骤3:生成优化后的查询语句

  • Write efficient SQL that leverages your database structure
  • Include comments explaining complex logic
  • Add performance considerations for large datasets
  • Provide alternative approaches if applicable
  • 编写可充分利用您数据库结构的高效SQL语句
  • 包含注释以解释复杂逻辑
  • 针对大型数据集添加性能考量建议
  • 如有适用场景,提供替代实现方案

Step 4: Explain and Test

步骤4:解释与测试

  • Explain the query logic in plain English
  • Suggest how to test or validate results
  • Offer tips for performance optimization
  • If you want, generate a test script or sample data
  • 用直白易懂的语言解释查询逻辑
  • 建议如何测试或验证查询结果
  • 提供性能优化技巧
  • 如有需要,生成测试脚本或示例数据

Usage Examples

使用示例

Example 1: Query from Schema File
Upload your database_schema.sql file and say:
"Generate a query to find users who signed up in the last 30 days
and had at least 5 active sessions"
Example 2: Query from Diagram Description
"Here's my database: Users table (id, email, created_at), Sessions table
(id, user_id, timestamp, duration). Generate a query for average session
duration per user in January 2026."
Example 3: Complex Analysis Query
"Create a BigQuery query to analyze our revenue by region and customer tier,
including year-over-year growth rates."
示例1:基于架构文件生成查询
上传您的database_schema.sql文件并说明:
“生成一个查询语句,找出过去30天内注册且至少有5次活跃会话的用户”
示例2:基于图表描述生成查询
“我的数据库包含:Users表(id, email, created_at)、Sessions表(id, user_id, timestamp, duration)。生成一个查询2026年1月每位用户平均会话时长的语句。”
示例3:复杂分析查询
“创建一个BigQuery查询语句,按地区和客户层级分析我们的收入,包括同比增长率。”

Key Capabilities

核心功能

  • Multi-Dialect Support: Works with BigQuery, PostgreSQL, MySQL, Snowflake, SQL Server
  • File Reading: Reads schema files, SQL dumps, and data documentation
  • Query Optimization: Suggests indexes, partitioning, and performance improvements
  • Explanation: Breaks down queries for learning and documentation
  • Testing: Can generate test queries and sample data scripts
  • Script Execution: Create executable SQL scripts for your database
  • 多方言支持:兼容BigQuery、PostgreSQL、MySQL、Snowflake、SQL Server
  • 文件读取:可读取架构文件、SQL备份文件和数据文档
  • 查询优化:提供索引、分区及性能提升建议
  • 逻辑解释:拆解查询语句,便于学习和文档记录
  • 测试支持:可生成测试查询语句和示例数据脚本
  • 脚本执行:创建可在您的数据库中执行的SQL脚本

Tips for Best Results

最佳使用建议

  1. Provide context: Share your database schema or structure
  2. Be specific: Clearly describe what data you need and any filters
  3. Mention database: Specify which SQL dialect you're using
  4. Include constraints: Mention data volume, time ranges, and performance needs
  5. Request format: Ask for the query result format if you need specific output
  1. 提供上下文:分享您的数据库架构或结构
  2. 明确需求:清晰描述您需要的数据及任何筛选条件
  3. 指定数据库:说明您使用的SQL方言
  4. 说明约束:提及数据量、时间范围和性能要求
  5. 要求格式:如果需要特定输出格式,请说明

Output Format

输出格式

You'll receive:
  • SQL Query: Production-ready SQL code with comments
  • Explanation: What the query does and how it works
  • Performance Notes: Optimization tips and considerations
  • Test Script (if requested): Sample data and validation queries

您将收到:
  • SQL查询语句:带有注释的可用于生产环境的SQL代码
  • 解释说明:查询语句的功能及工作原理
  • 性能注意事项:优化技巧和相关考量
  • 测试脚本(按需提供):示例数据和验证查询语句

Further Reading

拓展阅读