Determining Optimal Packaging for Christmas Gifts
 

Given two tables, playground.gifts and playground.packages, write a SQL query to match each gift to the smallest package it fits into based on dimensions. A gift fits in a package if its dimensions are less than or equal to those of the package. A package is considered smaller than another if its volume is smaller. Each package can hold only one gift. Produce a table with columns: package_type and number, where number indicates how many gifts are matched to each package_type. Exclude package types not used. Sort the result by package_type in ascending order. Assume every gift fits in at least one package and no two packages have the same volume.

These are the tables to query for this question:
playground.gifts
  • id int
  • gift_name string
  • length int
  • width int
  • height int
playground.packages
  • package_type string
  • length int
  • width int
  • height int
Your answer should include these columns:
  • package_type varchar
  • number integer

Querying is only for logged in users!

Write Your Query Here (you can run selections by highlighting!)

Query Results

No queries have been run yet.