FastPrepDaily Successful Transactions Per Department
Problem · Database

Daily Successful Transactions Per Department

Easyinfosys logoinfosysNEW GRADONSITE INTERVIEW

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.

products
ColumnMeaning
product_idUnique product identifier
dept_idDepartment identifier
priceListed product price
transactions
ColumnMeaning
product_idProduct sold or attempted
dept_idDepartment of the transaction
transaction_dateCalendar date of the transaction
priceTransaction price
statusTransaction outcome text

Table schema

MySQLPostgreSQLPandas

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.

ColumnTypeNullableDescription
product_idPKIntegerNo
dept_idIntegerNo
priceIntegerNo

transactions

One row per transaction attempt.

ColumnTypeNullableDescription
product_idIntegerNo
dept_idIntegerNo
transaction_dateDateNo
priceIntegerNo
statusTextNo

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
transaction_dateDateNo
department_idIntegerNo
successful_countIntegerNo

Row order: must match exactly. Numeric tolerance: 0.

Constraints

  • Each table has between 1 and 10^5 rows.
  • product_id is unique and non-null in products.
  • dept_id, price, transaction_date, and status are non-null.
  • A transaction is successful only when status is exactly successful.

More infosys problems