Question

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.

Homework Answers

Answer #1

Solution : Required SQL queries have been given below. Syntax has been checked.

Notes: in the given schema there are column names having "spaces", and special characters like "per-name".

In most of the the DBMS while querying such columns, the column name should be enclosed properly. For example in mySQL it should be enclosed in ` ` . For SQL server it should be enclosed in square brackets "[ ]". Following queries have been given using mySQL.

Ex #1: Find people who bought telephony products.

Select
  p.*
from
  Person p
  inner join Purchase pp on p.`per-name` = pp.buyer
  inner join Product pr on pp.product = pr.pname
where
  pr.category = 'Telephony'

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

Select
  p.*
from
  Person p
  inner join Purchase pp on p.`per-name` = pp.buyer
  inner join Product pr on pp.product = pr.pname
  inner join Company c on pr.manufacturer = c.cname
where
  c.country = 'America'

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

Select
  p.*
from
  Person p
  inner join Purchase pp on p.`per-name` = pp.buyer
  inner join Product pr on pp.product = pr.pname
  inner join Company c on pr.manufacturer = c.cname
where
  where c.country = 'America' and p.city = 'Seattle'

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

Select
  *
from
  Person p
where
  p.`per-name` in (
    Select
      buyer
    from
      Purchase
    where
      buyer in (
        Select
          seller
        from
          Purchase
      )
  )

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

Select
  p.*
from
  Person p
  inner join Purchase pp on p.`per-name` = pp.buyer
  inner join Product pr on pp.product = pr.pname
  inner join Company c on pr.manufacturer = c.cname
where
  c.`stock price` > 50
  or pp.seller = "Joe"
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
After reading the following article, how would you summarize it? What conclusions can be made about...
After reading the following article, how would you summarize it? What conclusions can be made about Amazon? Case 12: Amazon.com Inc.: Retailing Giant to High-Tech Player? (Internet Companies) Overview Founded by Jeff Bezos, online giant Amazon.com, Inc. (Amazon), was incorporated in the state of Washington in July 1994, and sold its first book in July 1995. In May 1997, Amazon (AMZN) completed its initial public offering and its common stock was listed on the NASDAQ Global Select Market. Amazon quickly...
Please read the article and answear about questions. Determining the Value of the Business After you...
Please read the article and answear about questions. Determining the Value of the Business After you have completed a thorough and exacting investigation, you need to analyze all the infor- mation you have gathered. This is the time to consult with your business, financial, and legal advis- ers to arrive at an estimate of the value of the business. Outside advisers are impartial and are more likely to see the bad things about the business than are you. You should...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary rivals? How will the acquisition of Reebok by Adidas impact the structure of the athletic shoe industry? Is this likely to be favorable or unfavorable for New Balance? 2- What issues does New Balance management need to address? 3-What recommendations would you make to New Balance Management? What does New Balance need to do to continue to be successful? Should management continue to invest...
Wal-Mart Online Wal-Mart is one of the largest companies in America. It is definitely the largest...
Wal-Mart Online Wal-Mart is one of the largest companies in America. It is definitely the largest retailer, both in terms of the number of stores (8,970 worldwide in 2011) and the level of sales ($419 billion from the 2011 Annual Report). By pushing suppliers to continually reduce costs, Wal-Mart is known for pursuing low prices and the stores often attract customers solely in-terested in lower prices. With Wal-Mart’s expansion into groceries, the company has be-come the largest retail grocer in...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how the firms resources incompetencies support the given pressures regarding costs and local responsiveness. Describe entry modes have they usually used, and whether they are appropriate for the given strategy. Any key issues in their global strategy? casestudy: Atlanta, June 17, 2014. Sea of Delta employees and their families swarmed between food trucks, amusement park booths, and entertainment venues that were scattered throughout what would...