Skip to content
CodeKruPro

Order totals that do not match their items

SQLMedium-Hard

An order's total should equal the sum of qty times price over its items. Return three columns for every order where the two differ: the order id, the stored total, and the items value. An order with no items has an items value of 0.

Rows can come back in any order. Column names do not matter; the values do.

Sample database: Shop: customers, orders, order items and payments

Four tables of an online shop. customers (id, name, email, city, created_at): the product requires an email, but in this data it may be NULL or empty; city is optional. orders (id, customer_id, total, status, created_at): status is PAID, PENDING or CANCELLED. order_items (id, order_id, product, qty, price): one row per order line, worth qty times price. payments (id, order_id, amount, status): status is SUCCESS or FAILED. Dates are text in the form YYYY-MM-DD. No foreign keys are enforced, so the data may hold mistakes.

customers
idnameemailcitycreated_at
1Asha Raoasha@mail.inPune2026-01-02
2Ravi Kumarravi@mail.inDelhi2026-01-05
3Meena Iyermeena@mail.inChennai2026-01-09
4John DsouzaNULLMumbai2026-02-01
5Fatima Sheikhravi@mail.inDelhi2026-02-14
6Karan Singhkaran@mail.inNULL2026-03-01
7Lata Menonlata@mail.inPune2026-03-20
8Nisha PaulKochi2026-04-02
orders
idcustomer_idtotalstatuscreated_at
100111500PAID2026-03-01
10022800PAID2026-03-02
100332200PAID2026-03-03
10049450PAID2026-03-04
10051300CANCELLED2026-03-05
100621250PAID2026-03-06
10073600PAID2026-03-07
10085999PENDING2026-03-08
10092800PAID2026-03-02
order_items
idorder_idproductqtyprice
11001Keyboard11000
21001Mouse2250
31002Headset1800
41003Monitor12000
51004Cable3150
61005Mouse1300
71006Keyboard11000
81006Mouse pad1150
91006Cable1100
101007Webcam1600
111009Headset1800
121012Charger1500
payments
idorder_idamountstatus
50110011500SUCCESS
5021002800SUCCESS
50310032200SUCCESS
5041004450SUCCESS
50510061250SUCCESS
50610061250SUCCESS
5071007600FAILED
5081009800SUCCESS
SQL (SQLite)

Run shows your rows. Submit compares them with the expected rows.

This question is part of Pro+

Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.

See Pro+

Already have Pro+? Sign in