Question 22

Average cost per rental transaction

Instruction
  • Write a query to return the average cost on movie rentals in May 2020 per transaction.

Table: payment

Movie rental payment transactions table

   col_name   | col_type
--------------+--------------------------
 payment_id   | integer
 customer_id  | smallint
 staff_id     | smallint
 rental_id    | integer
 amount       | numeric
 payment_ts   | timestamp with time zone

Sample results

        avg
--------------------
 1.234567

Solution

postgres
SELECT AVG(amount)
FROM payment
WHERE  DATE(payment_ts) >= '2020-05-01'
AND DATE(payment_ts) <= '2020-05-31';

Explanation

This query calculates the average payment amount for the month of May 2020. It selects the "amount" column from the "payment" table and filters the results to only include payments made between May 1st and May 31st of 2020. The "AVG" function then calculates the average of all the payment amounts within that time period.

Copied

Last Submission

postgres

No submission yet for this engine. Run and submit your query to save it here.

Copied
Expected results

Submit a query to compare against expected output.