Question: You will need to write SQL queries over the database schema created by the commands below. CREATE TABLE Company (cname varchar(30) primary key, country varchar(30));


You will need to write SQL queries over the database schema created by the commands below. CREATE TABLE Company (cname varchar(30) primary key, country varchar(30)); CREATE TABLE Product (pname varchar(30) primary key, price float, category varchar(30), manufacturer varchar(30) references Company); CREATE TABLE Sales (pname varchar(30) references Product, sold int, month varchar(10), primary key (pname, month)); CREATE TABLE Employees (empID integer primary key, name varchar (50), phone varchar(12), managerID integer); CREATE TABLE Projects(empID integer, project varchar(40)); Write the following SQL queries. Q3: Compute the total number of sales for each product, only for those products that have sold more than 2 items in total. In your result, the first column should have the product name, and the second column should list the number of sold items for that product. Submit the query in file Q3.sql. Q4: For each country, compute how many 'Gadgets' products it produces. In your result, the first column should have the name of the country, and the second column the number of Gadgets products for that country. Submit the query in file Q4.sql. Q5: For each category, compute how many countries produce products in that category. In your result, the first column should have the category, and the second column should have the appropriate number. Submit the query in file Q5.sql. Q6: For each project, list how many employees are assigned to it. In your result, the first column should list all projects, and the second column should have the appropriate numbers. Submit the query in file Q6.sql. Q7: For each product, find the month during which the product had the most sales out of the year. For example, if out of all the months of the year, Gizmo had the most sales in February, then the tuple (Gizmo, February) should be in the result. Submit the query in file Q7.sql. Q8: The following query has a problem and produces a syntax error. SELECT COUNT (pname), category FROM Product GROUP BY category WHERE COUNT (pname) >= 2 Rewrite the query to fix the problem and submit the rewritten query in file Q8.sql. Q9: Determine whether the following statement is true or false: You can always move a condition from the WHERE clause to the HAVING clause. Format your answer in a query as follows: SELECT answer where answer is either true or false. Submit your answer as a query in file Q9.sql
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
