Question
Consider a database schema with three relations: - Parts (pid:integer, pname:string, year:integer, price:integer) -Suppliers (sid:integer, sname: string, state:string, zipcode:string) -Orders (pid:integer, sid:integer, quantity:integer) The description
Consider a database schema with three relations:
- Parts (pid:integer, pname:string, year:integer, price:integer)
-Suppliers (sid:integer, sname: string, state:string, zipcode:string)
-Orders (pid:integer, sid:integer, quantity:integer)
The description is as follows: a factory keeps a database with parts that it uses, the suppliers of those parts, and purchase orders. Each part is uniquely identified by pid. Each part has a string description pname, year of fabrication and price per unit. Parts are provided by suppliers, and each supplier is uniquely identified by sid. Each supplier has a name sname, and it operates at the given state and zipcode. The company has a number of orders for parts, and each order contains the pid of the part ordered, the sid of the supplier from which the part is ordered, and the quantity ordered. You are allowed flexibility on the exact attribute types you use for your schema, as long as they reasonably match the specification above (e.g., in terms of number types, string types). Include the schema definition in your submission in a file called schema.sql.
Question 1
Write a PL/SQL function that takes a price as argument and returns the pid of the part that has the third- nearest price to the one given. Note that nearest can be either higher or lower. In case there are multiple parts with that property, choose the one with higher year. If there is still a tie, choose the one with highest pid.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started