Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases DeMYSTiFieD

Authors: Andy Oppel

2nd Edition

0071747990, 978-0071747998

More Books

Students also viewed these Databases questions