consider the following schema:
Product(pid, name, type, manufacturer, price)
key: pid
Buys(cid, pid)
key: cid and pid together
Customer(cid, cname, age, gender)
key: cid
1) write the following query in relational algebra; find the names of all customers who have purchased all products manufactured by sears.
2)write the following in sql: find the names of all the customers who have not purchased the most expensive product.
3)write the following query in sql: find the best selling products (in terms of the total sales price) per gender.
4) write the following query in sql: find the type of products with the highest difference in the total sales between males and females customers.
1.
SELECT c.cname from customer c, product p, buys b where p.pid = b.pid AND p.cid = c.cid AND p.manufacturer = "Sears";
2.
SELECT c.cname from customer c, product p, buys b where p.pid = b.pid AND p.cid = c.cid AND p.price NOT IN (select MAX(Price) from product);
3.
SELECT p.name from
(SELECT p.name, SUM(p.price) as Price FROM customer c, product p, buys b where p.pid = b.pid AND p.cid = c.cid GROUP BY c.gender Order BY SUM(p.price) desc) where Price IN
(SELECT MAX(p.price) from
(SELECT p.name, SUM(p.price) as Price FROM customer c, product p, buys b where p.pid = b.pid AND p.cid = c.cid GROUP BY c.gender Order BY SUM(p.price) desc));
consider the following schema: Product(pid, name, type, manufacturer, price) key: pid Buys(cid, pid) key: cid and...
consider the following schema: Product(pid, name, type, manufacturer, price) key: pid Buys(cid, pid) key: cid and pid together Customer(cid, cname, age, gender) key: cid 1) write the following query in relational algebra; find the names of all customers who have purchased all products manufactured by sears. 2)write the following in sql: find the names of all the customers who have not purchased the most expensive product. 3)write the following query in sql: find the best selling products (in terms of...
Given the following relational schema, write queries in SQL to answer the English questions. There is a shipment database on the MySQL server. You can also use the DDL for MySQL. You must only submit the SQL for your answers but you can include the query output as well to help the TA with marking. Customer(cid: integer, cname: string, address: string, city: string, state: string) Product(pid: integer, pname: string, price: currency, inventory: integer) Shipment(sid: integer, cid: integer, shipdate: Date/Time) ShippedProduct(sid:...
Given the following relational schema, write queries in SQL to answer the English questions. There is a shipment database on the MySQL server. You can also use the DDL for MySQL. You must only submit the SQL for your answers but you can include the query output as well to help the TA with marking. Customer(cid: integer, cname: string, address: string, city: string, state: string) Product(pid: integer, pname: string, price: currency, inventory: integer) Shipment(sid: integer, cid: integer, shipdate: Date/Time) ShippedProduct(sid:...
Consider the following relational schema of the company’s database. Use Tuple Relational Calculus (TRC) & Domain Relational Calculus (DRC) expression to answer each of the following three questions (Step by step brief description is appreciated if possible) PRODUCT (pid, stock, supplier) CLIENT (cid, name, address, city) ORDER (orderno, date, quantity, pid, cid) Question 1: Find the number of orders for products that are being ordered in quantities smaller than 100 items by customers living in Madrid. Provide solutions expressed both...
Given the following relational schema, write queries in SQL to answer the English questions. There is a shipment database on the MySQL server. You can also use the DDL for MySQL. You must only submit the SQL for your answers but you can include the query output as well to help the TA with marking. Customer(cid: integer, cname: string, address: string, city: string, state: string) Product(pid: integer, pname: string, price: currency, inventory: integer) Shipment(sid: integer, cid: integer, shipdate: Date/Time) ShippedProduct(sid:...
Given the following relational schema, write queries in SQL to answer the English questions. The Access Database for the schema is available, as is a DDL file. It is also available on the MySQL server. You must only submit the SQL for your answers. You can get your answers without using a DBMS or by using Access or MySQL. Customer(cid: integer, cname: string, address: string, city: string, state: string) Product(pid: integer, pname: string, price: currency, inventory: integer) Shipment(sid: integer, cid:...
Consider a database schema consisting of two tables, Employee (ID, Name, Address), Project(PID, Name, Deadline), Assign (EID, PID, Date). Assign.EID is a foreign key referencing employee's ID and Assign.PID is a foreign key reference the project. Write the SQL query for 1. Find Projects that are not assigned to any employees(PID and Name of the project).
Consider a database with the following schema: Person ( name, age, gender ) name is a key Frequents ( name, pizzeria ) (name, pizzeria) is a key Eats ( name, pizza ) (name, pizza) is a key Serves ( pizzeria, pizza, price ) (pizzeria, pizza) is a key Write SQL clauses for the queries given: e. Find all pizzerias that are frequented by only females or only males. f. For each person, find all pizzas the person eats that are...
Consider the following schema: Suppliers (sid: integer, sname: varchar, address: varchar) Parts (pid: integer, pname: varchar, color: varchar) Catalog (sid: integer, pid: integer, cost: real) that order) (1pt.) Where sid is the supplier’s id (primary key in Suppliers), pid is the part’s id (primary key in Parts), and sid together with pid is the primary key of Catalog. The Catalog relation lists the prices charged for parts by Suppliers. Write the following queries using relational algebra: Find the names...
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...