Daily Successful Transactions Per Department
Problem statement
The table products stores one row per product, including that product's department. The table transactions stores one row per product sale attempt, including the transaction date, department, price, and status.
For every distinct transaction date and every department that appears in products, count the successful transactions. A transaction is successful when its status is exactly successful.
Return transaction_date, department_id, and successful_count. Include department-date pairs with zero successful transactions. Order rows by transaction_date ascending, then department_id ascending.
What the interview report shared
There is a products table with productId, deptId, and price, and a transaction table with productId, deptId, transactionDate, price, and status. Find, for every day, for each department, the count of successful transactions.
| Column | Meaning |
|---|---|
product_id | Unique product identifier |
dept_id | Department identifier |
price | Listed product price |
| Column | Meaning |
|---|---|
product_id | Product sold or attempted |
dept_id | Department of the transaction |
transaction_date | Calendar date of the transaction |
price | Transaction price |
status | Transaction outcome text |
Table schema
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
products
One row per product.
| Column | Type | Nullable | Description |
|---|---|---|---|
| product_idPK | Integer | No | — |
| dept_id | Integer | No | — |
| price | Integer | No | — |
transactions
One row per transaction attempt.
| Column | Type | Nullable | Description |
|---|---|---|---|
| product_id | Integer | No | — |
| dept_id | Integer | No | — |
| transaction_date | Date | No | — |
| price | Integer | No | — |
| status | Text | No | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| transaction_date | Date | No | — |
| department_id | Integer | No | — |
| successful_count | Integer | No | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
- Each table has between
1and10^5rows. product_idis unique and non-null inproducts.dept_id,price,transaction_date, andstatusare non-null.- A transaction is successful only when
statusis exactlysuccessful.