Back to questions

Compressed Mode Alibaba SQL Interview Question

Compressed Mode

Alibaba SQL Interview Question

You're given a table containing the item count for each order on Alibaba, along with the frequency of orders that have the same item count. Write a query to retrieve the mode of the order occurrences. Additionally, if there are multiple item counts with the same mode, the results should be sorted in ascending order.

Clarifications:

  • : Represents the number of items sold in each order.
  • : Represents the frequency of orders with the corresponding number of items sold per order.
  • For example, if there are 800 orders with 3 items sold in each order, the record would have an of 3 and an of 800.

Effective June 14th, 2023, the problem statement has been revised and additional clarification have been added for clarity.

Table:

Column NameType
item_countinteger
order_occurrencesinteger

Example Input:

item_countorder_occurrences
1500
21000
3800

Example Output:

mode
2

Explanation:

Based on the example output, the value of 1000 corresponds to the highest frequency among all item counts. This means that item count of 2 has occurred 1000 times, making it the mode of order occurrences.

The dataset you are querying against may have different input & output - this is just an example!

Input

Output