logo

Back to questions

Trade In Payouts

Easy

Apple has a trade-in program where their customers can return the old iPhone device to Apple and Apple gives the customers the trade-in value (known as payout) of the device in cash.

For each store, write a query of the total revenue from the trade-in. Order the result by the descending order.

Table:

Column NameType
transaction_idinteger
model_idinteger
store_idinteger
transaction_datedate

Example Input:

transaction_idmodel_idstore_idtransaction_date
111251201/01/2022
211351201/01/2022

Table:

Column NameType
model_idinteger
model_namestring
payout_amountinteger

Example Input:

model_idmodel_namepayout_amount
111iPhone 11200
112iPhone 12350
113iPhone 13450
114iPhone 13 Pro Max650

Example Output:

store_idpayout_total
512800

Explanation:

Store 512 had 2 trade-ins: iPhone 12 and 13, so the total payout is 800 (350 + 450).

PostgreSQL 14

Refer friends to get bonus content & cool prizes.