FastPrepFind the Dominant Seller
Problem · Database

Find the Dominant Seller

MediumSquadStack.ai logoSquadStack.aiNEW GRADOA

Problem statement

The table sellers stores one row per seller, and orders stores completed orders.

For each seller, compute total_revenue = SUM(item_qty * item_rate) across that seller's orders. A seller with no orders has total revenue 0.

A seller is dominant when their total revenue is strictly greater than the combined total revenue of all other sellers. Return every dominant seller's seller_id and total_revenue, ordered by seller_id ascending.

sellers
ColumnMeaning
seller_idUnique seller identifier
seller_nameSeller name
orders
ColumnMeaning
order_idUnique order identifier
seller_idSeller that received the order
item_qtyNumber of items sold
item_rateExact rate per item

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.

sellers

One row per seller.

ColumnTypeNullableDescription
seller_idPKIntegerNo
seller_nameTextNo

orders

Completed orders attributed to sellers.

ColumnTypeNullableDescription
order_idPKIntegerNo
seller_idIntegerNo
item_qtyIntegerNo
item_rateDecimalNo

Foreign key: seller_id sellers(seller_id)

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
seller_idIntegerNo
total_revenueDecimalNo

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

Constraints

  • The sellers table has between 1 and 10^5 rows.
  • The orders table has between 0 and 2 * 10^5 rows.
  • seller_id and order_id are unique and non-null.
  • Every orders.seller_id references an existing seller.
  • seller_name, item_qty, and item_rate are non-null.
  • 0 <= item_qty <= 10^6.
  • 0 <= item_rate <= 10^9, with at most 12 digits after the decimal point.

More SquadStack.ai problems