advanced-sql
Skill0 starsChanged 4 days agoMITArchived repositoryView on GitHub
Design, review, debug, test and optimize SQL queries, analytical schemas, semantic models, SQL pipelines, SQL-based statistics, ML feature queries and governed SQL/AI workloads. Use for joins, CTEs, window or recursive queries, query plans and dialect selection. Complement data-dimensional-modeling for business grain and database-design for physical indexing/engines. Do not require a warehouse migration or use every advanced feature.
In this repository23 other files it gives its agents.
- AGENTS.mdAGENTS.md
- adrSkill
- bend-proofSkill
- content-writingSkill
- database-designSkill
- data-decision-scienceSkill
- data-dimensional-modelingSkill
- data-lifecycleSkill
- data-operationsSkill
- data-slicingSkill
- data-statisticsSkill
- data-storytellingSkill
- evidence-researchSkill
- graph-protocolSkill
- gui-design-thinkingSkill
- marimo-notebooksSkill
- project-adoptionSkill
- repository-workSkill
- requirementsSkill
- software-design-thinkingSkill
- software-factorySkill
- testingSkill
- visual-designSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 10
Method: Start with the actual engine/version, target question and relevant tables.
- Very specific: line 18
Express clearly: prefer the simplest readable set-based query.
- Very specific: line 30
Avoid treating SELECT *, indexes, partitioning, caching, materialized views, OBT and streaming as universal optimizations.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Advanced SQL — semantic correctness → measured query efficiency
Authority: The SQL representation and execution of an approved question, data contract or transformation. $requirements owns business rules; $data-dimensional-modeling owns analytic fact/metric meanings; $database-design owns engine and persistent physical-design choices; $data-statistics owns statistical inference; $data-decision-science owns ML decision validity; $data-lifecycle/$data-operations own running pipelines. Do not silently redefine these contracts to speed up a query.
Method: Start with the actual engine/version, target question and relevant tables. Use only relevant references: query semantics, model selection, execution plans and dialects, SQL pipelines and semantic layers, SQL in science, AI and emerging syntax. See book-derived concept map.
The eight-step SQL review (scale to the task)
- Question and consumer: state output and why it matters; distinguish a descriptive query, operational transformation, prediction dataset and write.
- Inputs and grain: identify source authority, row meaning, unique keys, cardinalities, source version, null/duplicate policy, and event/effective/ingest time. Record what is unknown.
- Model fit: choose existing normalized, star, snowflake, wide, lakehouse or semantic/graph representation by actual read/write patterns and change needs. Do not remodel when a query suffices.
- Relational correctness: map each join's multiplicity, filtering stage, grouping level, aggregation and null semantics. Guard against silent row multiplication and denominator changes.
- Express clearly: prefer the simplest readable set-based query. Use CTEs to structure reasoning, windows for row-relative calculations, recursion for bounded traversals, and subqueries/
EXISTSfor membership. CTEs do not automatically materialize or speed up queries. - Validate results: compare with small known-answer fixtures or an independent query; exercise 0/1/many matches, NULLs, ties, duplicate or late events and time boundaries. Check both row grain and aggregate reconciliation.
- Measure before tuning: inspect real plan and runtime/cost/bytes at representative parameters and volume. Change one mechanism at a time; recheck output equivalence and concurrent/load behavior. Mark unmeasured claims unknown.
- Operationalize conditionally: for shared SQL models add ownership, lineage, permissions, freshness, incremental/backfill semantics, tests, monitoring and compatible releases. For one-off analysis, keep a reproducible query and assumptions; no mandatory orchestration.
Critical guards
- A correct SQL syntax or schema is not proof of correct business meaning. Know one row represents what, especially before
JOIN,COUNT,DISTINCT,AVG, ratios and windows. LEFT JOINcan become an effective inner join when right-side filters are placed inWHERE; anINNER JOINcan multiply facts. Test both risks.ROW_NUMBER()and top-N need a deterministic total order to resolve ties. WindowORDER BYand window frame (ROWS/RANGE/GROUPS) are distinct; do not assume a cumulative frame expresses a whole partition.- SQL uses three-valued logic:
NULLis not an ordinary value. Be careful withNOT INwhen the subquery contains NULL; preferNOT EXISTSfor anti-membership when appropriate.COUNT(*)differs fromCOUNT(col). - Casts, overflow, decimal precision, timestamps/timezones, implicit coercion, division by zero, collation, isolation and dialect behavior need explicit treatment when relevant.
- Avoid treating
SELECT *, indexes, partitioning, caching, materialized views, OBT and streaming as universal optimizations. Protect correctness, authorization and maintainability first. - A model feature must be available at decision cutoff; event time alone does not establish availability. A successful SQL training query is not evidence of model validity or causal impact.
- SQL-triggered generative AI may disclose governed content to an external service. Require permission, cost ceiling, grounding, output evaluation, and vendor/version-specific confirmation before enabling it.
Focused output contract
Consumer / question / intended output:
SQL engine + version + dialect constraints (known/unknown):
Input sources / owners / row grain / cardinality / time semantics:
Query/model choice, alternative and reason:
SQL + expected result shape and key invariants:
Small known-answer test + adversarial edge cases:
Observed plan, runtime and cost | Not measured:
Permissions / lineage / freshness / replay / rollback if operational:
Known | Assumed | Unknown | decision pending:Scope and provenance: This method synthesizes Advanced SQL: Implementing Modern Data Solutions and ML Applications by Rui Machado, Hélder Russa and Pedro Esmeriz (O'Reilly, 2026), using the public publisher table of contents and chapter previews, then adds explicitly identified Mimir engineering checks. The book's full text is not included in this repository. These are original, practical instructions, not verbatim book examples and not a claim of exhaustive full-text coverage.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

