Question

In: Computer Science

Consider the following database schema:                Product(maker, model, type)                PC(model, speed

Consider the following database schema:

               Product(maker, model, type)

               PC(model, speed, ram, hd, rd, price)

               Laptop(model, speed, ram, hd, screen, price)

               Printer(model, color, type, price)

Give SQL statement for each of the following:

(Grouping and Aggregation) Write the following queries in SQL:

  1. Find the average speed of laptops costing over $2000.
  2. Find the average price of PC’s and laptops made by manufacturer “D”.
  3. Find, for each manufacturer, the average screen size of its laptops.
  4. Find the manufacturers that make at least three different models of PC.
  5. Find, for each manufacturer who sells PC’s, the maximum price of a PC.
  6. Find, for each speed of PC above 800, the average price.
  7. Find the average hard-disk size of a PC for all those manufacturers that make printers.

Solutions

Expert Solution

1a)

select avg(speed)
from laptop
where price::numeric > 2000;

2a)

select avg(A.price::decimal)
from
   (( select pc.price
       from pc, product
       where pc.model = product.model and product.maker = 'D'
      )
   UNION
   ( select laptop.price
       from laptop, product
       where laptop.model = product.model and product.maker = 'D'))
as A;

3a)

select product.maker, avg(laptop.screen)
from laptop, product
where product.model = laptop.model
group by product.maker;

4a)

select product.maker
from pc,product
where pc.model = product.model
group by maker
having count(maker) >= 3;

5a)

select product.maker
from pc,product
where pc.model = product.model
and pc.price >= ALL(select pc.price from pc);

6a)

select speed, avg(pc.price::decimal)
from pc
where speed > 2.0
group by speed;

7a)

select avg(B.hd)
from (
   (select product.maker
   from printer, product
   where printer.model = product.model)
INTERSECT
   (select product.maker
   from pc,product
   where pc.model = product.model)) as A,
   (select product.maker, pc.hd
   from product, pc
   where product.model = pc.model) as B
where A.maker = B.maker;


Related Solutions

Consider the following database schema:                Product(maker, model, type)                PC(model, speed
Consider the following database schema:                Product(maker, model, type)                PC(model, speed, ram, hd, rd, price)                Laptop(model, speed, ram, hd, screen, price)                Printer(model, color, type, price) Give SQL statement for each of the following: (Subqueries, Join operations) Write the following queries in SQL: Find the makers of PC’s with a speed of at least 1200. Find the printers with the highest price. Find the laptops whose speed is lower than that of any PC. Find the model number...
SQL query exercises: Consider the following database schema:                Product(maker, model, type)              &
SQL query exercises: Consider the following database schema:                Product(maker, model, type)                PC(model, speed, ram, hd, rd, price)                Laptop(model, speed, ram, hd, screen, price)                Printer(model, color, type, price) Consider the Drivers-Cars-Reserves DB for a small rental car company:                Drivers(id, name, rating, age)                Cars(vin, maker, model, year, color)                Reserves(did, vin, date) Give SQL statement each of the following operations: Find the colors of cars reserved by Smith. Find all id’s of drivers who have a...
For the given database schema. Answer the following questions. Company Database customer(cust_id, name, address) product(product_id, product_name,...
For the given database schema. Answer the following questions. Company Database customer(cust_id, name, address) product(product_id, product_name, price, quantity) transaction(trans_id, cust_id, time_date) product_trans(product_id, trans_id) Identify the primary keys and foreign keys for the relations and specify at least two different types of integrity constraints that would be applicable for different relations given.
Consider the following universal relation THE following database schema is in 4NF. What can you infer...
Consider the following universal relation THE following database schema is in 4NF. What can you infer about multi-valued dependencies? A C D A B C E E F A-It does not have multi-valued dependencies. B-The multi-valued dependency A ->-> C does not hold. If the multi-valued dependency A ->-> C held, the database would not be in 4NF. C-The multi-valued dependency A ->-> B does not hold. If the multi-valued dependency A ->-> B held, the database would not be...
Question 2: consider the following library relational database schema Write a program segment to retrieves the...
Question 2: consider the following library relational database schema Write a program segment to retrieves the list of books that became overdue yesterday and that prints the book title and borrower name for each. 1- Use JDBC with Java as the host language
[Q.4] Answer the following questions You are invited as a database architect to develop database schema...
[Q.4] Answer the following questions You are invited as a database architect to develop database schema for maintaining patient information for the NYU medical group (make necessary assumptions for the data requirements if needed). Each physician in the Lehman medical group is uniquely identified by physicianID o Each physician must have first name, and last name, and phone number Each patient is identified by patientID o Each patient must have first name, and last name, phone number, and insurance card...
Consider the following database schema: LIKE(person, sport), PRACTICE(person, sport), where person and sport are keys in...
Consider the following database schema: LIKE(person, sport), PRACTICE(person, sport), where person and sport are keys in both tables. The table LIKE gives the sports a person likes, the table PRACTICE gives the sports a person practices. We assume that a person likes at least one sport and practices at least one sport. We assume also that a person does not like a sport if the sport is not listed among the sports that person likes Express the following queries in...
Consider the following database schema: LIKE(person, sport), PRACTICE(person, sport), where person and sport are keys in...
Consider the following database schema: LIKE(person, sport), PRACTICE(person, sport), where person and sport are keys in both tables. The table LIKE gives the sports a person likes, the table PRACTICE gives the sports a person practices. We assume that a person likes at least one sport and practices at least one sport. We assume also that a person does not like a sport if the sport is not listed among the sports that a person likes Express the following queries...
Consider the following database schema: LIKE(person, sport), PRACTICE(person, sport), where person and sport are keys in...
Consider the following database schema: LIKE(person, sport), PRACTICE(person, sport), where person and sport are keys in both tables. The table LIKE gives the sports a person likes, the table PRACTICE gives the sports a person practices. We assume that a person likes at least one sport and practices at least one sport. We assume also that a person does not like a sport if the sport is not listed among the sports that person likes. Express the following queries in...
Consider the following relational database schema:             employee(employee-name, employee-id, street, e-city)             works(employee-
Consider the following relational database schema:             employee(employee-name, employee-id, street, e-city)             works(employee-id, company-id, salary)             company(company-name, company-id, c-city)             manages(employee-id, manager-id) Specify the following queries on this database schema using the relational operators we discussed in class. Write your answers on a separate sheet of paper in the order that they are specified below. Retrieve the name and address of employees who work for First Bank Corporation. Retrieve the name, street address, and city of residence of all employees...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT