SShortSingh.
Back to feed

15 SQL window function practice problems with answers to run immediately

0
·2 views

The article argues that window functions separate basic SQL users from those who truly understand the language, and that practice problems are the best way to master them. It uses a single small sales table so the examples can run across Postgres, MySQL 8+, SQL Server, and SQLite 3.25+. Key points include how PARTITION BY restarts counting per group, how a missing ORDER BY affects running totals, and why LAG returns NULL on the first row unless a default is supplied. It also warns that LAST_VALUE only looks up to the current row by default and needs an UNBOUNDED FOLLOWING frame. The author has compiled 15 problems covering ranking, running totals, LAG/LEAD, and NTILE, each with an answer and explanation.

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 ·

VBR or CBR for MP3: Choosing the Right Bitrate Mode for Music, Podcasts and Voice

A practical guide weighs constant bitrate (CBR) against variable bitrate (VBR) for MP3 encoding, explaining that CBR assigns the same data budget to every frame while VBR allocates bits according to audio complexity. VBR generally yields smaller files at similar quality, making it a good fit for music libraries, while CBR suits streaming, editing, speech, and older hardware that may misread VBR durations. The article notes that some common beliefs, such as VBR always sounding better, are overstated, and that re-encoding a lossy MP3 into VBR does not improve quality. It recommends encoding from the highest-quality source available and offers a quick decision guide based on use case.

0
ProgrammingDEV Community ·

Rails 8 app splits front ends: Turbo for contractors, lean Stimulus-only page for customers

The founder of an estimate and invoice app for small trade businesses describes building two separate front ends in one Rails 8 monolith. Contractors, who use the app daily as an installed PWA, get Hotwire with Turbo and Turbo Streams for fast, app-like navigation and live updates. Customers, who open a single text-message link once, get a dedicated layout with only Stimulus and a few controllers, with no Turbo, ActionCable or third-party scripts. The customer page targets under 50 KB of gzipped JavaScript, and forms there use plain POST and redirect round trips. The heavy signature controller is loaded on demand, only when a sign block is present or the visitor first taps Draw.

0
ProgrammingDEV Community ·

A Four-Bucket Framework for Triaging Technical Debt at Startups

Fast-growing startups often accept shortcuts such as hardcoded values, skipped validation, and untested services to meet deadlines, and that trade-off can be a practical survival tactic early on. Problems arise when debt piles up without classification, leading teams either to over-refactor working code or to ignore messy code until it fails under peak load. The article proposes sorting debt into four categories: toxic debt in critical flows like authentication or payments needs immediate repair, friction debt that slows daily development should be refactored iteratively, dormant debt in rarely changed code is best left alone, and blocker debt that constrains major launches is a strategic product decision. To keep shortcuts visible, it recommends tagging debt directly in code with metadata, using Python decorators and standardized TODO markers, and enforcing those tags in CI pipelines.

0
ProgrammingDEV Community ·

Converting cURL Commands to Laravel HTTP Client Code with a Browser Tool

A Dev Talk tool converts cURL commands into Laravel Http facade code directly in the browser, aiming to remove the error-prone manual translation of API requests. Developers can copy requests from browser DevTools or API docs and paste them into the converter, which accepts multi-line commands and produces code with helpers such as withToken(), asForm() and attach(). The tool offers options for response style, ->throw() handling and whether browser-specific headers are kept. The article notes the page does not list supported curl flags, so generated code should be reviewed rather than trusted blindly. It also advises rotating any real tokens pasted into such tools and using placeholders where possible.