Write a query to return the average cost on movie rentals in May 2020 per transaction.
Table:
payment
payment
payment_id
customer_id
staff_id
rental_id
amount
payment_ts
16077
279
2
1019
0.99
2020-05-31 03:05:07-07
16078
280
1
1014
4.99
2020-05-31 02:39:16-07
16079
281
2
650
2.99
2020-05-28 19:45:40-07
16080
281
2
754
2.99
2020-05-29 10:18:59-07
16081
282
2
48
1.99
2020-05-25 06:20:46-07
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.