SShortSingh.
Back to feed

SQL Tutorial: How to Calculate Month-over-Month Growth Using LAG()

0
·2 views

Data analyst Michael Nocito published a technical tutorial on August 7, 2026, explaining how to write reliable month-over-month growth queries in SQL. The guide covers the core growth formula — current month minus prior month, divided by prior month — and how the LAG() window function retrieves the previous row's value. Nocito highlights three common traps that silently produce wrong results: integer division, an empty first month, and missing months in the data. The critical distinction he emphasizes is that LAG() fetches the previous row, not the previous calendar month, meaning a gap in the data causes it to compare non-adjacent months. All examples were tested in SQLite using a 12-row dataset deliberately missing April, making it reproducible on any machine running SQLite 3.25 or later.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

AgnosticBrain adds a protected layer to stop AI from overwriting your manual edits

A knowledge management project called agnosticBrain has introduced a three-layer ownership system to address a blind spot in Andrej Karpathy's LLM Wiki pattern, which Karpathy published in April 2026. The original pattern splits a personal knowledge vault into raw sources (read-only for the LLM) and a wiki directory (fully maintained by the LLM), but assumes the human never edits the wiki directly. In practice, users do refine AI-generated notes by hand, and subsequent LLM ingests can silently overwrite those edits. AgnosticBrain solves this by adding a third directory called curated/, where manually refined notes are stored and treated as strictly off-limits for any AI agent or automated operation. Users move a note into curated/ via a /curate command, permanently protecting its contents from being altered during ingests or any other pipeline task.

0
ProgrammingDEV Community ·

Developer Forks OpenCode to Build Node-Based Multi-Agent AI Workflow Tool

A developer has released OpenFlow, an open-source project forked from OpenCode's harness, designed to enable multi-agent AI workflows instead of single prompt-agent interactions. The tool lets users build reusable pipelines by creating agent cards with designated roles — such as planner, architect, or coder — and linking them in chains. OpenFlow retains OpenCode's bring-your-own-key model and supports multiple AI providers. The developer cited frustrations with the unreliability and limitations of current AI models as motivation for building a more structured, collaborative approach. The project is available on GitHub and is still under active development.

0
ProgrammingDEV Community ·

Five Quick Checks to Verify AI-Generated SQL Before Trusting the Output

AI assistants can produce syntactically valid SQL queries in seconds, but a query that runs successfully has only passed a grammar check — not a correctness check. Common errors include fan-out from joins that multiply rows, wrong filters, and incorrect denominators, all of which return clean result sets with wrong numbers. A practical five-step review process, ordered from cheapest to most involved, can catch these mistakes in roughly two minutes using only the existing database. A key example shows an AI-written revenue query returning 1,830 instead of the correct 1,330, because a LEFT JOIN doubled rows for orders with split refunds. Comparing row counts before and after a join is highlighted as a fast, reliable first check to detect such fan-out errors.

0
ProgrammingDEV Community ·

Guide Shows How to Build a Voice AI Phone Agent for Local Businesses Using n8n

A technical guide published on DEV Community outlines how to create an AI-powered voice agent that handles inbound calls for local service businesses such as plumbers and dentists. The system integrates Anthropic's Claude, ElevenLabs text-to-speech, and Twilio Programmable Voice, orchestrated through a self-hosted n8n workflow. It is designed to automate appointment scheduling, lead qualification, and payment capture without human intervention. Developers can package the solution as a monthly subscription service and sell it to small businesses as a virtual phone receptionist. The guide estimates a build time of 12 to 16 hours and emphasizes that a repeatable client-acquisition funnel is the primary revenue driver for such an agency.