The Vote Tally

An easy SQL interview practice problem on DataDriven. Write the query and run it against a real database, with instant feedback.

Domain
SQL
Difficulty
easy
Seniority
L5

Problem

The transactions table records one row per sale, with the amount charged and the day it was made. Give the total taken in on each day of September 2026, earliest day first.

One product, every day it sold, and the money it brought in.

Tables

transactions

Columns: transaction_id INTEGER, user_id INTEGER, product_id INTEGER, quantity INTEGER, total_amount REAL, transaction_date TEXT

transactions: 10 of 200 rows
transaction_iduser_idproduct_idquantitytotal_amounttransaction_date
10671971001223.462026-02-02
11342941050336.932026-03-03
12013911099450.42026-04-04
12684881148563.872026-05-05
13355851197002026-06-06
14026821246290.812026-07-07
146977912953104.282026-08-08
153687613444117.752026-09-09
160397313935-452026-01-10
1670107014421144.692026-02-11

products

Columns: product_id INTEGER, product_name TEXT, category TEXT, price REAL, rating REAL, in_stock INTEGER

products: 10 of 200 rows
product_idproduct_namecategorypriceratingin_stock
1001Basic Device 1XBooks17.522.71
1050Deluxe Bundle 2XClothing25.054.41
1099Pro Unit 3XHome & Kitchen32.582.11
1148Ultra Tool 4XCollectibles40.113.81
1197Essential Set 5XToys47.641.51
1246Classic System 6XBeauty03.21
1295Smart Gadget 7XAutomotive62.74.90
1344Eco Kit 8XGarden70.232.61
1393Turbo Pack 9XMusic77.764.30
1442Premium Widget 10XElectronics85.2921

Expected output

First 5 of 9 rows
transaction_datedaily_revenue
2026-09-011087.59
2026-09-02723.9
2026-09-031690.26
2026-09-04966.36
2026-09-05602.67

Worked solution and explanation

What this really is

Under the finance costume, this question is about grain. The table has one row per sale, and the answer needs one row per day, so what you are really being asked is whether you notice those are different. In September 2026 the 3rd and the 7th each have two sales and the 6th has three. A query that just lists the month's sales returns 12 lines with repeated dates, and each line shows one sale instead of the day's takings. The other bait is the products table sitting next to transactions: nothing in it belongs in the answer.

Building it

Step 1: Scope to the month

Keep rows with transaction_date >= '2026-09-01'. The dates are ISO strings, so comparing them as text is the same as comparing them as dates. Nothing in the table is dated after today, so the lower bound alone covers the whole month to date.

Step 2: Fold each day into a single figure

Use GROUP BY transaction_date with SUM(total_amount). On the 6th, three sales of 238.98, 1,208.82 and 616.14 become one 2,063.94, and the 3rd and the 7th each collapse from two lines to one. That folding is the whole answer.

Step 3: Lay the days out in calendar order

Finish with ORDER BY transaction_date. The result is read as a timeline, so the order is part of the answer.

Daily revenue for the month
SELECT
    transaction_date,
    SUM(total_amount) AS daily_revenue
FROM transactions
WHERE transaction_date >= '2026-09-01'
GROUP BY transaction_date
ORDER BY transaction_date;

One table, one month filter, one grouped sum, ordered by day.

Raw sales (wrong)
Selecting transaction_date and total_amount for the month returns one line per sale. The 6th shows up three times, and the 3rd and the 7th twice each. Someone still has to add them up by hand.
Daily totals (right)
Adding GROUP BY transaction_date and SUM(total_amount) folds those lines into nine rows, one per day, so you can read the column straight down.

Common follow-up questions