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 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 $ 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 $
Example:
Given:
name price quantity
Pencil
Rubber
Notebook
Pen
you query should return:
I quantity
We can buy all pencils and notebooks. This gives products in total that will cost exactly $
All the items can be bought with $
Assume that:
the products table has at most rows;
price column can only contain integers from to inclusive; quantity column can only contain integers from to inclusive;
Sum of values in quantity column is smaller than or equal to
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
