write-analytical-sql

Generate analytical SQL queries with CTEs, window functions, and aggregations.

9|3|Updated Jun 13, 2026
One-click install
npx skills add https://github.com/Sir-chawakorn/sanook-cli --skill write-analytical-sql
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: write-analytical-sql
Source: https://github.com/Sir-chawakorn/sanook-cli/tree/main/skills/write-analytical-sql
Command: npx skills add https://github.com/Sir-chawakorn/sanook-cli --skill write-analytical-sql

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill eliminates the frustration of writing complex analytical SQL queries by ensuring dialect-specific syntax accuracy and preventing common logical errors like join fan-out or incorrect window function framing.

Core Features & Use Cases

  • Dialect Translation: Seamlessly convert SQL queries between Postgres, BigQuery, Snowflake, and Databricks.
  • Analytical Logic: Expertly construct CTEs, window functions, and aggregations for reporting and business intelligence.
  • Use Case: Use this skill to transform a raw transaction table into a clean, monthly revenue report with running totals and period-over-period growth metrics.

Quick Start

Use the write-analytical-sql skill to generate a BigQuery-compatible query that calculates the 30-day rolling average of active users per region using a CTE.

Frequently Asked Questions about write-analytical-sql

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write analytical SQL with window functions and CTEs without causing join fan-out?

To generate a rolling average in BigQuery, use a CTE to aggregate base metrics, then apply a window function with the appropriate date math frame. This Skill generates dialect-specific syntax for calculating rolling averages and period-over-period growth accurately.

Can I translate a complex SQL query from Postgres to Snowflake?

Yes, this Skill supports cross-warehouse query translation between Postgres, BigQuery, Snowflake, and Databricks. It ensures semantic correctness by adapting dialect-specific syntax for date math, deduplication, and window function framing across platforms.

What is the best way to calculate period-over-period growth metrics in SQL?

The best way to calculate period-over-period growth in SQL is using CTEs and window functions to structure clean aggregations. This Skill generates readable queries that implement business logic and handle nulls to ensure accurate reporting and growth metric calculations.

Does this SQL generation approach support Databricks and BigQuery syntax?

Yes, this SQL generation approach fully supports Databricks and BigQuery syntax. It generates accurate analytical SQL queries by applying dialect-specific syntax for date math, deduplication, and window function framing across these and other major data warehouses.

Why does my SQL window function return incorrect results across different database dialects?

SQL window functions return incorrect results across dialects due to incorrect framing and syntax differences. This Skill prevents these errors by validating join grains, handling nulls, and applying the correct date math and deduplication logic for each specific database dialect.