Question

using SQL Assume the relations shown below (underlined attributes are primary and foreign keys): merchants(mid, name,...

using SQL

Assume the relations shown below (underlined attributes are primary and foreign keys):


merchants(mid, name, city, state)


products(pid, name, category, description)


sell(midpid, price, quantity_available)


orders(oid, shipping_method, shipping_cost)


contain(oid,pid)


customers(cid, fullname, city, state)


place(cidoid, order_date)


 


For each of the following questions write a SQL query:


List names and sellers of products that are no longer available (quantity=0)


List names and descriptions of products that are not sold.


How many customers bought SATA drives but not any routers between 2009 and 2019?


HP has a 20% sale on all its Networking products.


What did Uriel Whitney order from Acer on October 13, 2016? (make sure to at least retrieve product names and prices).


List the annual total sales for each company (sort the results along the company and the year attributes).


Which company had the highest annual revenue and in what year?


On average, what was the cheapest shipping method used in 2016?


What is the best sold ($) category for each company?


For each company find out which customers have spent the most and the least amounts.


 


 


 


General Guidelines


Your tables must have primary or foreign key constraints along with:


Products name constraint: Printer, Ethernet Adapter, Desktop, Hard Drive, Laptop, Router, Network Card, Super Drive, Monitor


Products category constraint: Peripheral, Networking, Computer


Sell price constraint: between 0 and 100,000


Sell quantity_available constraint: between 0 and 1,000


Orders shipping_method constraint: UPS, FedEx, USPS


Orders shipping_cost constraint: between 0 and 500


Place order_date: between 2005-1-1 and 2019-12-31


0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. List names and sellers of products that are no longer available (quantity=0)

SELECT names,mid FROM Merchant as M,sell as S WHERE M.mid = S.sid AND S.quantity_available = 0;

2.List names and descriptions of products that are not sold.

SELECT names,description FROM Product as P,sell as S WHERE P.pid = S.pid AND S.quantity_available > 0;

3.How many customers bought SATA drives but not any routers between 2009 and 2019?

SELECT count(pid) FROM Product as P1,Product as P2,Contain as C,Place as P WHERE P.pid = C.pid AND P1.name = 'Hard drive' and P2.name != 'Router' AND C.oid = P.oid AND YEAR(P.order_date) between '2009' and '2019';

4.HP has a 20% sale on all its Networking products.

*********Question not clear***************

5.What did Uriel Whitney order from Acer on October 13, 2016? (make sure to at least retrieve product names and prices).

SELECT P.name, S.price FROM Product as P,Customer as C, Place as P1 , Contain as C, Sell as S, Merchant as M WHERE P1.cid = C.cid AND P1.oid = C.oid AND P.pid = C.pid AND P.pid = S.sid AND S.mid = M.mid AND M.name = 'Acer' AND C.fullname= 'Uriel Whitney' AND P1.order_date = '2016-*10-13';

6.List the annual total sales for each company (sort the results along the company and the year attributes).

*********Question not clear***************

7.On average, what was the cheapest shipping method used in 2016?

SELECT min(avg(shipping_cost)) FROM orders as O, Place as P WHERE O.oid = P.pid AND YEAR(P.order_date=2016) GROUP BY O.shipping_method;

8.What is the best sold ($) category for each company?

SELECT max(sum(S.price)) FROM Products as P1, SELL as S, Place as P, Contain as C WHERE P1.pid = S.pid AND S.pid = C.pid AND C.oid = P.oid GROUP BY P.category;

9.For each company find out which customers have spent the most and the least amounts.

SELECT min(sum(S.price)),max(sum(S.price)) FROM Customer as C,Place as P, Sell as S, Contain as C , Merchants as M WHERE S.cid = P.cid AND P.oid = C.oid AND C.pid = S.pid GROUP BY M.name;

Add a comment
Know the answer?
Add Answer to:
using SQL Assume the relations shown below (underlined attributes are primary and foreign keys): merchants(mid, name,...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Below is the database schema for a company. Primary keys are underlined. Customers (CustomerID, CompanyName, Phone,...

    Below is the database schema for a company. Primary keys are underlined. Customers (CustomerID, CompanyName, Phone, BalanceDue) Oders (Orderid, orderdate, customerid, freightamount) Orderdetails (oderid, productid, qtyordered, price) Products (productid, productname, qtyinstock, suggestedprice, minstocklevel) Given this SQL statement: Select * From Customers Inner Join Orders on Orders.CustomerID=Customers.CustomerID Where Orders.CustomerID is Null; Which of the following statement is correct? It is a SQL select statement that will list the ProductName for all products where the Qtyinstock is less than the total QtyOrdered...

  • NEED THE SQL QUERIES ASAP PLEASE(LIKE 1 HOUR) THE ONES WITH ID ARE PRIMARY KEYS OR...

    NEED THE SQL QUERIES ASAP PLEASE(LIKE 1 HOUR) THE ONES WITH ID ARE PRIMARY KEYS OR FOREIGN etc Customer [ CustID, LastName, FirstName, Address, City, State, Zip, Phone, Fax, Email] Product [ ProdID, Description, Color, Size, Pack] Sales [ TransID, CustID, ProdID, Price, Quantity, Amount] Write SQL statement to produce a list of unique products and their prices from the Sales table. Please ensure that the products do not repeat. Write an SQL statement to list ProdID and Description for...

  • The primary keys are underlined. The foreign keys are denoted by asterisks (*). Description of the...

    The primary keys are underlined. The foreign keys are denoted by asterisks (*). Description of the schema: • person — keeps track of the people who borrow books from the library. The attributes contain personal and contact information. • author — keeps track of personal information about authors. • publisher — keeps track of the publisher information. To keep it simple, most of the attributes have been truncated in the sample database. 1 trivial dependencies are things like X→X or...

  • Given the following relational database schema (primary keys are bold and underlined). Answer questions 2.1 to 2.4 Orde...

    Given the following relational database schema (primary keys are bold and underlined). Answer questions 2.1 to 2.4 Orders(orderld, customerld, dateOrdered, dateRequired, status) Customer(customerld, customerLastName, customerStreet, customerCity, customerState, customer Lip OrderDetails(orderld.productld, quantity, lineNumber, amount) Products(productld, name, description, quantity, unitPrice) Account(accountNumber, customerld, dateOpened, creditCard, mailingStreet, mailingCity, mailingState, mailingZip) 2.1 (2 Points) List all possible foreign keys. For each foreign key list both the referencing and referenced relations. 2.2 (2 Points) Devise a reasonable database instance by filling the tables with data of...

  • This is extra information about the shopping database given to answer this question: For many query...

    This is extra information about the shopping database given to answer this question: For many query questions we refer to the following database schema for a website that keeps track of what people like to buy or actually buy in different on-line supermarkets. (Think of something like a cross-store loyalty card system.) customer(cID, cName, street, city) Customers with unique cID and other attributes store(sID, sName, street, city) Stores with a unique ID and other attributes. Stores with the same name...

  • Instructions: For each case below, graphically represent entities and relationships between entities. Include primary keys, foreign...

    Instructions: For each case below, graphically represent entities and relationships between entities. Include primary keys, foreign keys where appropriate. For each entity add a couple of attributes (fields) and then provide a brief statement explaining why each entity (table) is in 3NF. Data for an information technology conference needs to be collected. The conference has a variety of sessions scheduled over a two-day period. All attendees must register for the sessions they plan to attend. Some speakers are presenting only...

  • I NEED TO WRITE THE FOLLOWING QUERIES IN MYSQL (13)Next, grant to a user admin the read privileges on the complete descr...

    I NEED TO WRITE THE FOLLOWING QUERIES IN MYSQL (13)Next, grant to a user admin the read privileges on the complete descriptions of the customers who submitted no orders. For example, these are the customers who registered themselves and submitted no orders so far. The granted privilege cannot be propagated to the other users. 0.3 (14)Next, grant to a user admin the read privileges on information about the total number of orders submitted by each customer. Note, that some customers...

  • An online company sells hundreds of office supply products on its e-Commerce store. It has asked...

    An online company sells hundreds of office supply products on its e-Commerce store. It has asked you to design and implement a sales order processing system which will be used by users in our Operations department to process sales orders. Here is an overview of the sales order process. Customers make purchases by placing orders. Each customer has a customer number and profile (such as name, shipping address). To simplify the matter, each time an order is placed, only one...

  • Please read the article and answer about questions. You and the Law Business and law are...

    Please read the article and answer about questions. You and the Law Business and law are inseparable. For B-Money, the two predictably merged when he was negotiat- ing a deal for his tracks. At other times, the merger is unpredictable, like when your business faces an unexpected auto accident, product recall, or government regulation change. In either type of situation, when business owners know the law, they can better protect themselves and sometimes even avoid the problems completely. This chapter...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT