Total revenue from text amounts
An SQL exercise from Querydrill. Solve it with a SQL editor in your browser, checked on the rows it returns and again on changed data, and it is checked the moment you submit.
The task
From Priya in Finance: "The amount column is text, like $1,200.00 and ' 30.50'. What is our total revenue from paid payments? Count a payment as paid whatever the capitals or spaces in its status." Return one number, rounded to 2 decimals.
What this exercise teaches
Numbers stored as text are one of the most common data problems. Convert them once, explicitly, before you add them up.
A hint if you get stuck
Strip the $ and the commas with REPLACE, TRIM the spaces, then CAST(... AS REAL). Match the status with LOWER(TRIM(status)) = 'paid'.
This exercise is part of Pro
Pro unlocks all 60 exercises, with worked solutions and progress saved to your account. The free exercises work without an account.
You create a free account first, so Pro is attached to it.
Monthly is charged today and then every month until you cancel, in one click from your account page. Lifetime is one payment with no renewals. Full refund within 14 days of paying.