Write Advanced SQL Window Functions
Generate complex SQL window functions for analytics, ranking, and cumulative calculations. Perfect for advanced data analysis queries.
Prompt Template
Variables to Customize
[TABLE_NAME] The name of the database table to query
Example: sales_transactions
[COLUMN_DETAILS] Relevant columns with their data types
Example: transaction_id (INT), customer_id (INT), transaction_date (DATE), amount (DECIMAL), product_category (VARCHAR)
[DATABASE_SYSTEM] The specific database system being used
Example: PostgreSQL
[ANALYSIS_REQUIREMENTS] What business questions need to be answered
Example: Calculate running totals by customer, rank customers by monthly sales, and identify top 3 products per category
[WINDOW_FUNCTION_TYPE] Specific window functions needed
Example: ROW_NUMBER(), RANK(), SUM() OVER(), LAG(), LEAD()
Example Output
Pro Tips for Best Results
- Always specify ORDER BY in window functions for consistent results across database restarts
- Use PARTITION BY strategically to reset calculations at logical boundaries
- Test window functions with edge cases like NULL values and duplicate rankings
- Consider using CTEs to break complex window function queries into readable components
- Monitor query performance and add appropriate indexes on partitioning and ordering columns
Tags
Want 500+ Expert Prompts?
Get the Premium Prompt Pack — organized, tested, and ready to use.
Get it for $29Related Prompts You Might Like
Optimize SQL Query Performance
You are a senior database performance engineer specializing in SQL query optimization. I need you to analyze and optimiz...
Merge Data from Multiple Sources
I need to merge data from multiple sources and need your help creating a comprehensive data integration plan. Please ana...
Write Complex Excel Formulas
You are an Excel formula expert. I need you to create a complex Excel formula for the following scenario: **Data Contex...
Build Employee Performance Tracker Spreadsheet
Create a comprehensive employee performance tracker spreadsheet for [DEPARTMENT] with [NUMBER_OF_EMPLOYEES] employees. T...
Remove Duplicates from Dataset
I need help removing duplicates from my dataset. Please analyze the following data and provide a comprehensive deduplica...
Handle Missing Data Values
You are an expert data scientist specializing in data preprocessing and missing data analysis. I need comprehensive guid...