Question: You are given a table products with the following structure: create table products ( name varchar ( 2 0 ) primary key, price integer not

You are given a table products with the following structure:
create table products
(
name varchar (20) primary key, price integer not null, quantity integer not null
);
It represents the product types that can be bought in a shop. Each row of the table contains information about a product:
name - unique key, name of the product type
price - price per single item of this product in dollars
quantity - number of items of this product available in the shop
What is the maximum number of items that can be bought by spending at most $100? The items bought can be of different types and their number can't exceed their availability in the shop.
Write an SQL query that finds this number. The result table should comprise one column, quantity, that contains an integer describing the maximum number of items that can be bought with $100
Example:
1. Given:
name |price | quantity
Pencil 330
Rubber 53
Notebook 53
Pen 620
you query should return:
I quantity
32
We can buy all 30 pencils and 2 notebooks. This gives 32 products in total that will cost exactly $100.
All the items can be bought with $100.
Assume that:
the products table has at most 100 rows;
price column can only contain integers from 1 to 200 inclusive; quantity column can only contain integers from 1 to 100 inclusive;
Sum of values in quantity column is smaller than or equal to 100

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!