Question

In: Computer Science

Consider the following schema: product (pname, price, category, manufacturer) Purchase (buyer, seller, store, product) Company (cname,...

Consider the following schema:

product (pname, price, category, manufacturer)

Purchase (buyer, seller, store, product)

Company (cname, stock price, country)

Person(per-name, phone number, city)

Write a suitable SQl for the following:

Ex #1: Find people who bought telephony products.

Ex #2: Find names of people who bought American products

Ex #3: Find names of people who bought American products and they live in Seattle.

Ex #4: Find people who have both bought and sold something.

Ex #5: Find people who bought stuff from Joe or bought products from a company whose stock prices is more than $50.

Solutions

Expert Solution

The SQL queries based on the schema are given as follows:

Ex.1: The names of who buyed telephony products

Query:

Select Person.per-name FROM Person, Purchase, Product WHERE Person.per-name=Purchase.buyer AND Product=Product.pname AND Product.category="telephony".

So, the above query will obtain the desired results.

Ex.2: Names of people who bought American products

Query: Select Person.per-name FROM Person, Purchase, Company WHERE Person.per-name=Purchase.buyer AND Company=Company.cname AND Company.country="USA"

So, the above query will obtain the desired results.

Ex.3: Names of people who bought American products and they live in Seattle

Query: Select Person.per-name FROM Person, Purchase, Company WHERE Person.per-name=Purchase.buyer AND Company=Company.cname AND Company.country="USA" AND Person.city="Seattle"

So, the above query will obtain the desired results.

Ex 4: Name people who have both bought and sold something.

Query:

Select Person.per-name FROM Person, Purchase WHERE Person.per-name=Purchase.buyer AND Person.per-name=Purchase.seller

So, the above query will obtain the desired results.

Ex 5: Name people who bought stuff from Joe or bought products from a company whose stock prices is more than $50

Query:

Select Person.per-name FROM Perseon, Purchase, Company,Product WHERE Product=Product.pname AND Person.per-name=Purchase.seller AND Purchase.seller="Joe" OR Company.stock price>50.

So, the above query will obtain the desired results.

---------------------------------------Please Upvote---------------------------------------------------------------------------------


Related Solutions

What is a purchase price reduction? When the buyer and seller agree to reduce the purchase...
What is a purchase price reduction? When the buyer and seller agree to reduce the purchase price of real property after agreeing on price terms, but before the sale is closed. When an insolvent buyer receives credit from a seller for the purchase of property, and the seller later reduces the purchase price and relieves the buyer of some of the debt associated with the original purchase. When the buyer and seller agree to reduce the purchase price of real...
What is maximum acceptable purchase price? What is value split between a buyer and a seller?
What is maximum acceptable purchase price? What is value split between a buyer and a seller?
Seller and buyer enter into a contract for buyer to purchase 1,000 pot holders for $1,000....
Seller and buyer enter into a contract for buyer to purchase 1,000 pot holders for $1,000. Assume for purposes of this question the contract is in writing and otherwise meets all requirements of the Statute of Frauds. Buyer breaches the contract and seller resells to a local company for $900. Discuss the remedies that are available to the seller
Buyer and Seller entered into a written agreement for Buyer to purchase real property, which property included a home, from Seller.
 Buyer and Seller entered into a written agreement for Buyer to purchase real property, which property included a home, from Seller. Under the terms of the purchase agreement, the risk of loss "shall remain with Seller until delivery of title." The purchase agreement was entered into on May 15 and called for closing on June 1, though the agreement did not say that time was of the essence. Seller chose this date for closing, in part, because that was the...
3- An option to purchase binds which of the following parties? a) Buyer only b) Seller...
3- An option to purchase binds which of the following parties? a) Buyer only b) Seller only c) Neither buyer nor seller d) Both buyer and seller please explain the answer you did not explain that earlier
Consider a buyer and seller who enter into a contract where the seller produces a good...
Consider a buyer and seller who enter into a contract where the seller produces a good and delivers it to the buyer for payment. At the time of making the contract, the seller is uncertain as to the actual cost of the project, and the situation is described by the following: Cost = 30 with probability 60% Cost = 70 with probability 20% Cost = 150 with probability 20% Before production occurs, the seller does learn the cost. The value...
Consider the following schema: Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost) write the following...
Consider the following schema: Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost) write the following queries in SQL: * Find the names of all suppliers who supply a green part. *Find the names of all suppliers who are from Illinois. *Find the names of all suppliers who sell a red part costing less than $100. *Find the names and colors of all parts that are green or red. In writing these queries you may make the following assumptions: a....
INRO TO DATABASES Consider the following Schema: Suppliers(sid: integer, sname: string, address: string) Parts(pid: integer, pname:...
INRO TO DATABASES Consider the following Schema: Suppliers(sid: integer, sname: string, address: string) Parts(pid: integer, pname: string, color: string) Catalog(sid: integer, pid: integer, cost: real) The Catalog relation lists the prices charged for parts by Suppliers. Write the following queries in SQL using join, nested queries and set operators. 1. Find names of suppliers who supply every red or green part. 2. Find the sids of suppliers who supply every red part or supply every green part. 3. Find sids...
Consider the following schema: Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost) In a plain...
Consider the following schema: Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost) In a plain text file, write the following queries in SQL: 1.Find the names of all suppliers who supply a green part. 2.Find the names of all suppliers who are from Illinois. 3.Find the names of all suppliers who sell a red part costing less than $100. 4.Find the names and colors of all parts that are green or red. In writing these (basic) queries you may...
Consider the following schema: Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost) In a plain...
Consider the following schema: Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost) In a plain text file, write the following queries in SQL: Find the names of all suppliers who supply a green part. Find the names of all suppliers who are from Illinois. Find the names of all suppliers who sell a red part costing less than $100. Find the names and colors of all parts that are green or red. In writing these queries you may make...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT