To 🔥 celebrate the holiday season, Also check out our NEWLY launched Annual plan (Up to 50% off). Use coupon code THANKSGIVING15 and enjoy additional 15% off all paid plans. Coupon expires at 2020/11/30 .
65. Movie revenue percentiles easy

Instruction

  • Write a query to return percentile distribution for the following movies by their total rental revenues in the entire movie catalog.
  • film_id IN (1,10,11,20,21,30).
  • A film can only belong to one category.
  • The order of your results doesn't matter.
  • Return the following columns: film_id, revenue, percentile

Table 1: film

       col_name       |  col_type
----------------------+--------------------------
 film_id              | integer
 title                | text
 description          | text
 release_year         | integer
 language_id          | smallint
 original_language_id | smallint
 rental_duration      | smallint
 rental_rate          | numeric
 length               | smallint
 replacement_cost     | numeric
 rating               | USER-DEFINED
 last_update          | timestamp with time zone

  

Table 2: rental

   col_name   | col_type
--------------+--------------------------
 rental_id    | integer
 rental_ts    | timestamp with time zone
 inventory_id | integer
 customer_id  | smallint
 return_ts    | timestamp with time zone
 staff_id     | smallint
 last_update  | timestamp with time zone

  

Table 3: inventory

Each row is unique; Inventoy_id is the primary key of the table

   col_name   | col_type
--------------+--------------------------
 inventory_id | integer
 film_id      | smallint
 store_id     | smallint
 last_update  | timestamp with time zone

  

Table 4: 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

film_id  | revenue | percentile
---------+---------+------------
      11 |   35.76 |         23
       1 |   36.77 |         24
      30 |   46.91 |         35

Subscribe for solution