sql-query

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

SQL Query

SQL查询

Generate SQL queries for data retrieval, analysis, and reporting.
生成用于数据检索、分析和报表制作的SQL查询语句。

Capabilities

功能特性

  • Generate SELECT, INSERT, UPDATE, DELETE queries
  • Build complex JOINs and subqueries
  • Aggregate data with GROUP BY and window functions
  • Optimize query performance
  • 生成SELECT、INSERT、UPDATE、DELETE查询语句
  • 构建复杂的JOIN和子查询
  • 使用GROUP BY和窗口函数进行数据聚合
  • 优化查询性能

Query Patterns

查询模式

Basic Select

基础查询

sql
SELECT column1, column2
FROM table_name
WHERE condition
ORDER BY column1
LIMIT 100;
sql
SELECT column1, column2
FROM table_name
WHERE condition
ORDER BY column1
LIMIT 100;

Aggregation

聚合查询

sql
SELECT category, COUNT(*) as count, AVG(price) as avg_price
FROM products
GROUP BY category
HAVING COUNT(*) > 10;
sql
SELECT category, COUNT(*) as count, AVG(price) as avg_price
FROM products
GROUP BY category
HAVING COUNT(*) > 10;

Window Functions

窗口函数

sql
SELECT
    name,
    department,
    salary,
    RANK() OVER (PARTITION BY department ORDER BY salary DESC) as rank
FROM employees;
sql
SELECT
    name,
    department,
    salary,
    RANK() OVER (PARTITION BY department ORDER BY salary DESC) as rank
FROM employees;

Best Practices

最佳实践

  1. Always use parameterized queries to prevent SQL injection
  2. Index columns used in WHERE and JOIN clauses
  3. Avoid SELECT * in production queries
  4. Use EXPLAIN to analyze query performance
  1. 始终使用参数化查询以防止SQL注入
  2. 为WHERE和JOIN子句中使用的列创建索引
  3. 在生产环境查询中避免使用SELECT *
  4. 使用EXPLAIN分析查询性能