SQL Quest › SQL Interview Questions › Conditional Logic

Calculated Columns

EasyFreeQuerying BasicsConditional Logic

Create new calculated columns from existing data. For each movie, show title, runtime (in minutes), runtime_hours (runtime divided by 60, rounded to 1 decimal), and revenue_per_minute (revenue_millions divided by runtime, rounded to 2 decimals). Exclude movies with NULL revenue. Sort by revenue_per_minute descending. Limit to 10 rows.

Solve it in the browser editor →

Runs on SQLite in your browser, graded against the expected result, no signup. A wrong answer gets a diagnosis, not just "incorrect". Free accounts get 10 free challenge solves, and this can be one of them.

Schema

movies

idtitleyeargenreratingvotesrevenue_millionsruntimedirector
1Guardians of the Galaxy2014Action8.1757074333.13121James Gunn
2Prometheus2012Adventure7485820126.46124Ridley Scott
3Split2016Horror7.3157606138.12117M. Night Shyamalan

Expected output: runtime_hours: 2.0, revenue_per_minute: 2.50

Hint

Use / for division and ROUND(expression, decimals) for rounding. Name columns with AS.

Concepts

SELECT Expressions ROUND

Practise the topic: SQL practice questions · CASE WHEN practice

Read the concept: SQL CASE WHEN tutorial

Related questions

Referred vs Organic: First-Month SpendMedium · FreeOrder Funnel ConversionHard · ProCard Decline Rate by PlanHard · ProComp Tier LabelsEasy · FreeMembership Display LabelsEasy · FreeRounded Revenue: Top 10 from 2015+Easy · Free

Where would this cost you points in an interview?

Ten questions, no signup: a Skillmap across nine SQL skills and the one to fix first.

Take the readiness test