Question

In: Computer Science

Import the northwind database and write sql statements for the following: List all supplier ids (no...

Import the northwind database and write sql statements for the following:

  1. List all supplier ids (no duplicates) for all products.
  2. List the product name and supplier id for all products that cost more than $20.
  3. List all products whose names start with letter "c" and are not discontinued.
  4. List each country name and the number of suppliers located in the country.
  5. List all supplier names, the number of products that each supplier provides (this column should be named as NumOfProducts), and the average price for the products provided by the same supplier (this column should be named as AvgPrice).
  6. Find all suppliers' name, city, and country for those who provide non-discontinued products.
  7. List all supplier names who provide at least two different products.
  8. Add a new product record to the products table. You must provide values for the following fields in the new product record: ProductID, productName, SupplierID, and CategoryID.
  9. Increase the reorder level by 20% and reduce the prices by 10% for all products
  10. Delete discontinued products.

Solutions

Expert Solution

  • List all supplier ids (no duplicates) for all products.
select DISTINCT SupplierID from Products;
  • List the product name and supplier id for all products that cost more than $20.
select ProductName,SupplierID from Products where UnitPrice > 20;
  • List all products whose names start with letter "c" and are not discontinued.
select * from Products where ProductName like 'c%' and Discontinued = 0;
  • List each country name and the number of suppliers located in the country.
select Country,COUNT(SupplierID) from Suppliers group by Country;
  • List all supplier names, the number of products that each supplier provides (this column should be named as NumOfProducts), and the average price for the products provided by the same supplier (this column should be named as AvgPrice).
select s.SupplierID,s.ContactName,COUNT(p.ProductID) as "NumOfProducts",AVG(p.UnitPrice) as "AvgPrice" from Products as p,Suppliers as s where p.SupplierID=s.SupplierID group by s.SupplierID;
  • Find all suppliers' name, city, and country for those who provide non-discontinued products.
select s.ContactName,s.City,s.Country from Products as p,Suppliers as s where p.SupplierID=s.SupplierID and p.Discontinued=0;
  • List all supplier names who provide at least two different products.
select s.SupplierID,s.ContactName from Products as p,Suppliers as s where p.SupplierID=s.SupplierID group by s.SupplierID having COUNT(p.ProductID)>=2;
  • Add a new product record to the products table. You must provide values for the following fields in the new product record: ProductID, productName, SupplierID, and CategoryID.

Here I am inserting sample value:

insert into Products(ProductID,ProductName,SupplierID,CategoryID) values(78,'Coffee',1,1);
  • Increase the reorder level by 20% and reduce the prices by 10% for all products
update Products set ReorderLevel=ReorderLevel+(0.2*ReorderLevel),UnitPrice=UnitPrice-(0.1*UnitPrice);
  • Delete discontinued products.
delete from Products where Discontinued=1;

Related Solutions

Write SQL queries below for each of the following: List the names and cities of all...
Write SQL queries below for each of the following: List the names and cities of all customers List the different states the vendors come from (unique values only, no duplicates) Find the number of customers in California List product names and category descriptions for all products supplied by vendor Proformance List names of all employees who have sold to customer Rachel Patterson
Write the SQL queries that accomplish the following tasks using the AP Database 9. Write a...
Write the SQL queries that accomplish the following tasks using the AP Database 9. Write a select statement to show the invoicelineitemdescriptions that have the total invoicelineitemamount >1000 and the number of accountno is >2. 10. Write a select statement that returns the vendorid, paymentsum of each vendor, and the number of invoices of each vendor, where paymentsum is the sum of the paymentotal column. Return only the top ten vendors who have been paid the most and the number...
Develop SQL statements to do the following: Query 1: List all employees by LXXX_EMP_ID, LXXX_EMP_NAME, LXXX_EMP_CITY,...
Develop SQL statements to do the following: Query 1: List all employees by LXXX_EMP_ID, LXXX_EMP_NAME, LXXX_EMP_CITY, LXXX_EMP_PHONE, LXXX_DEP_ID, order by LXXX_DEP_ID. Query 2: List all employees by LXXX_EMP_ID, LXXX_EMP_NAME, LXXX_DEP_NAME, order by LXXX_DEP_NAME. Query 3: List all employees by LXXX_EMP_ID, LXXX_EMP_NAME, LXXX_DEP_NAME who work for the "XXX_SALES" department. Query 4: List all employees by LXXX_EMP_ID, LXXX_EMP_NAME, LXXX_DEP_NAME, LXXX_EMP_CITY, LXXX_DEP_CITY who live and work in the same city, order by LXXX_DEP_CITY Query 5: List all employees by LXXX_EMP_ID, LXXX_EMP_NAME, LXXX_PROJ_TYPE, LXXX_START_DATE,...
Introdyction to database Topic SQL Q2) what is the purpose of following statements? SELECT DISTINCT SELECT...
Introdyction to database Topic SQL Q2) what is the purpose of following statements? SELECT DISTINCT SELECT DESC AND ORDER BY AS
Create the following SQL queries using the lyrics database below 1. List the first name, last...
Create the following SQL queries using the lyrics database below 1. List the first name, last name, and region of members who do not have an email. 2. List the first name, last name, and region of members who do not have an email and they either have a homephone ending with a 2 or a 3. 3. List the number of track titles that begin with the letter 's' and the average length of these tracks in seconds 4....
Please write the SQL statement for the following. I am using the Adventurework2014 database. 1. Create...
Please write the SQL statement for the following. I am using the Adventurework2014 database. 1. Create a login for AdventureWorks employees. An employee login should be composed of the first letter of a person's first name combined with their last name. In addition, the login should be all lower case characters. All the required information is located in Person.Person table. Employees can be identified by "EM" value in the PersonType field. The output should include BusinessEntityID, first name (FirstName), last...
In this assignment, you are required to write the SQL statements to answer the following queries...
In this assignment, you are required to write the SQL statements to answer the following queries using PostgreSQL system. The SQL statements comprising the DDL for Henry Books Database are given to you in two files. For that database, answer the following queries. Create the files Q1 to Q10 in PostgreSQL. Do follow the restrictions stated for individual queries. 1. List the title of each book published by Penguin USA. You are allowed to use only 1 table in any...
Write a SQL statement which joins the parts table with the supplier table and lists the...
Write a SQL statement which joins the parts table with the supplier table and lists the part_name, supplier_name for all parts in the part table. The supplier_id column in the suppliers table is the primary key in the suppliers table, and this key has been exported to the parts table where it is a foreign key. You should use an inner join for this query. Write a SQL statement which joins the parts table with the suppliers table and lists...
Write a SQL statement which joins the parts table with the supplier table and lists the...
Write a SQL statement which joins the parts table with the supplier table and lists the part_name, supplier_name for all parts in the part table. The supplier_id column in the suppliers table is the primary key in the suppliers table, and this key has been exported to the parts table where it is a foreign key. You should use an inner join for this query. Write a SQL statement which joins the parts table with the suppliers table and lists...
Which of the following is a database client software? Microsoft SQL Server 2017 Developer Microsoft SQL...
Which of the following is a database client software? Microsoft SQL Server 2017 Developer Microsoft SQL Server Management Studio Microsoft SQL Server Configuration Manager SQL Server Analysis Service Compared to Data Warehousing approach, the following are disadvantages of query-driven data integration approach, EXCEPT: __________. competition with local processing at source delay in query processing waste of storage space inefficient and potentially expensive for frequent queries What does OLAP stand for? Olympic Linear Algebra Problem On-Line Amazon Platform On-Line Analytical Processing...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT