Professional Definition: The ability to compose complex SQL programs that combine multi-level grouping, subquery-based relational comparisons, analytical window functions (e.g., RANK, LAG), counterfactual 'what-if' modeling via conditional expressions (CASE WHEN), and derived scalar mathematics to perform distributional or cross-cohort analysis.
Dimension Hierarchy: Query Reasoning->Relational and Logical Composition->nested aggregation and filter reasoning
Real Case
[Case 1]
Initial Environment: An enterprise analytics environment containing global session and conversion data. The schema allows for high-volume grouping but requires derived scalar logic to isolate exact efficiency margins.
Real Question: Find the page ID for the top three pages with the highest conversion rate, defined as the ratio of conversions to views, for the last month.
Real Trajectory: Identify the group unit (page_id). Construct the numerator and denominator independently. Apply the mathematical division securely inside a derived projection and structure an ordered descending retrieval based strictly upon the generated rate metric.
Real Answer: SELECT page_id, SUM(is_conversion)*1.0/NULLIF(COUNT(view_id), 0) AS conversion_rate FROM sessions WHERE timestamp >= '2024-12-01' GROUP BY page_id ORDER BY conversion_rate DESC LIMIT 3;
Why this demonstrates the capability: The agent must span disjoint structural components of a synthesized mathematical ratio, deploying arithmetic safeguards and executing definitive positional ranking strictly upon an abstract derivation.
[Case 2]
Initial Environment: A corporate database tracking sales performance includes an 'artist' table and a 'files' table that tracks size.
Real Question: Is the average file size for the artist 'Coldplay' greater than the average file size for 'Radiohead'?
Real Trajectory: Identify that two separate aggregations are needed for two different groupings. Compute scalar averages independently via symmetrical subqueries. Perform a relational comparison mapping between the aggregated components replacing a single entity lookup.
Real Answer: SELECT (SELECT AVG(file_size) FROM files WHERE artist_name = 'Coldplay') > (SELECT AVG(file_size) FROM files WHERE artist_name = 'Radiohead');
Why this demonstrates the capability: This tests processing relational comparison logic integrating two uniquely filtered subquery aggregates derived from the identical underlying architecture yielding a cross-cohort Boolean check natively.
[Case 3]
Initial Environment: A movie metadata relational hierarchy comprising 'title_ratings' listing base averages and vote volumes. Simulation parameters require projecting 'virtual' value shifts.
Real Question: Identify any movie in the current top 10 by average rating that would drop out of that list if we applied a penalty of -1.0 to the rating of any title with fewer than 5,000 votes.
Real Trajectory: Retrieve the precise baseline grouping. Cultivate a virtual state modifier operating a dynamic CASE constraint conditionally adjusting target scores. Isolate displaced variants explicitly using rigorous set exclusions matching reality elements omitted natively from the penalized logic array.
Real Answer: SELECT primaryTitle FROM title_basics JOIN (SELECT tconst FROM title_ratings ORDER BY averageRating DESC LIMIT 10) AS Reality ON title_basics.tconst = Reality.tconst EXCEPT SELECT primaryTitle FROM title_basics JOIN (SELECT tconst FROM title_ratings ORDER BY CASE WHEN numVotes < 5000 THEN averageRating - 1.0 ELSE averageRating END DESC LIMIT 10) AS Simulation ON title_basics.tconst = Simulation.tconst;
Why this demonstrates the capability: Exhibits advanced conceptual what-if simulation embedded within layered SQL metrics dynamically altering specific values through localized conditionals compared securely against grounded actuals.
Pipeline Execution Instructions
To synthesize data for this capability, you must strictly follow a 3-phase pipeline. Do not hallucinate steps. Read the corresponding reference file for each phase sequentially:
Phase 1: Environment Exploration
Read the exploration guidelines to discover raw knowledge seeds:
references/EXPLORATION.md
Phase 2: Trajectory Selection
Once Phase 1 is complete, read the selection criteria to evaluate the trajectory:
references/SELECTION.md
Phase 3: Data Synthesis
Once a trajectory passes Phase 2, read the synthesis instructions to generate the final data:
references/SYNTHESIS.md
1---2name: nested-aggregation-and-filter-reasoning3description: Skill: nested aggregation and filter reasoning4---56# Skill: nested aggregation and filter reasoning78## 1. Capability Definition & Real Case9* **Professional Definition**: The ability to compose complex SQL programs that combine multi-level grouping, subquery-based relational comparisons, analytical window functions (e.g., RANK, LAG), counterfactual 'what-if' modeling via conditional expressions (CASE WHEN), and derived scalar mathematics to perform distributional or cross-cohort analysis.10* **Dimension Hierarchy**: Query Reasoning->Relational and Logical Composition->nested aggregation and filter reasoning1112### Real Case13**[Case 1]**14* **Initial Environment**: An enterprise analytics environment containing global session and conversion data. The schema allows for high-volume grouping but requires derived scalar logic to isolate exact efficiency margins.15* **Real Question**: Find the page ID for the top three pages with the highest conversion rate, defined as the ratio of conversions to views, for the last month.16* **Real Trajectory**: Identify the group unit (page_id). Construct the numerator and denominator independently. Apply the mathematical division securely inside a derived projection and structure an ordered descending retrieval based strictly upon the generated rate metric.17* **Real Answer**: SELECT page_id, SUM(is_conversion)*1.0/NULLIF(COUNT(view_id), 0) AS conversion_rate FROM sessions WHERE timestamp >= '2024-12-01' GROUP BY page_id ORDER BY conversion_rate DESC LIMIT 3;18* **Why this demonstrates the capability**: The agent must span disjoint structural components of a synthesized mathematical ratio, deploying arithmetic safeguards and executing definitive positional ranking strictly upon an abstract derivation.19---20**[Case 2]**21* **Initial Environment**: A corporate database tracking sales performance includes an 'artist' table and a 'files' table that tracks size.22* **Real Question**: Is the average file size for the artist 'Coldplay' greater than the average file size for 'Radiohead'?23* **Real Trajectory**: Identify that two separate aggregations are needed for two different groupings. Compute scalar averages independently via symmetrical subqueries. Perform a relational comparison mapping between the aggregated components replacing a single entity lookup.24* **Real Answer**: SELECT (SELECT AVG(file_size) FROM files WHERE artist_name = 'Coldplay') > (SELECT AVG(file_size) FROM files WHERE artist_name = 'Radiohead');25* **Why this demonstrates the capability**: This tests processing relational comparison logic integrating two uniquely filtered subquery aggregates derived from the identical underlying architecture yielding a cross-cohort Boolean check natively.26---27**[Case 3]**28* **Initial Environment**: A movie metadata relational hierarchy comprising 'title_ratings' listing base averages and vote volumes. Simulation parameters require projecting 'virtual' value shifts.29* **Real Question**: Identify any movie in the current top 10 by average rating that would drop out of that list if we applied a penalty of -1.0 to the rating of any title with fewer than 5,000 votes.30* **Real Trajectory**: Retrieve the precise baseline grouping. Cultivate a virtual state modifier operating a dynamic CASE constraint conditionally adjusting target scores. Isolate displaced variants explicitly using rigorous set exclusions matching reality elements omitted natively from the penalized logic array.31* **Real Answer**: SELECT primaryTitle FROM title_basics JOIN (SELECT tconst FROM title_ratings ORDER BY averageRating DESC LIMIT 10) AS Reality ON title_basics.tconst = Reality.tconst EXCEPT SELECT primaryTitle FROM title_basics JOIN (SELECT tconst FROM title_ratings ORDER BY CASE WHEN numVotes < 5000 THEN averageRating - 1.0 ELSE averageRating END DESC LIMIT 10) AS Simulation ON title_basics.tconst = Simulation.tconst;32* **Why this demonstrates the capability**: Exhibits advanced conceptual what-if simulation embedded within layered SQL metrics dynamically altering specific values through localized conditionals compared securely against grounded actuals.3334## Pipeline Execution Instructions35To synthesize data for this capability, you must strictly follow a 3-phase pipeline. **Do not hallucinate steps.** Read the corresponding reference file for each phase sequentially:36371. **Phase 1: Environment Exploration**38 Read the exploration guidelines to discover raw knowledge seeds:39 `references/EXPLORATION.md`40412. **Phase 2: Trajectory Selection**42 Once Phase 1 is complete, read the selection criteria to evaluate the trajectory:43 `references/SELECTION.md`44453. **Phase 3: Data Synthesis**46 Once a trajectory passes Phase 2, read the synthesis instructions to generate the final data:47 `references/SYNTHESIS.md`
Run npx skillmds@latest add dingxingdi/nested-aggregation-and-filter-reasoning in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Skill: nested aggregation and filter reasoning It is listed under Data & Analytics on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
dingxingdi (@dingxingdi) published this skill. Their other Agent Skills are listed on their SkillMD profile.