Back to questions

Compressed Mean Alibaba SQL Interview Question

Compressed Mean

Alibaba SQL Interview Question

You're trying to find the mean number of items per order on Alibaba, rounded to 1 decimal place using tables which includes information on the count of items in each order ( table) and the corresponding number of orders for each item count ( table).

Table:

Column NameType
item_countinteger
order_occurrencesinteger

Example Input:

item_countorder_occurrences
1500
21000
3800
41000

There are a total of 500 orders with one item per order, 1000 orders with two items per order, and 800 orders with three items per order."

Example Output:

mean
2.7

Explanation

Let's calculate the arithmetic average:

Total items =

Total orders =

Mean =

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

Input

(PostgreSQL)

Output