Skip to content
Quantoros

Using the payments table: how much do we receive in cash payments (total dollars) each day? Return the date and total,…

SQLLevel: IntermediateSQL scenarios

Using the payments table: how much do we receive in cash payments (total dollars) each day? Return the date and total, in date order.

Table definitions (from the source exercise):

CREATE TABLE payments(payment_id INTEGER PRIMARY KEY, customer_id INTEGER, payment_date TEXT, amount REAL, method TEXT);
Hints
  • Define one output row and the source-table keys.
  • Check duplicates, NULLs and the order of filtering and aggregation.

Answer

Approach: Filter method = 'cash' in WHERE, group by the date.

SELECT payment_date, SUM(amount) AS total_cash
FROM payments
WHERE method = 'cash'
GROUP BY payment_date
ORDER BY payment_date;

The source uses SQLite with a MySQL compatibility layer. Date and string functions are dialect dependent; the query is preserved as published.

Source and licence: SQL Practice Lab — Ebrahim Sharifi · MIT

Related questions