Lab 2
Lab 2
each country and each city and where the country and city are not null. Order the
result set by country in descending order and by city in ascending order.
(customers)
3) Write a query that will count how many orders were created starting from October
10th, 2003 and September 9th, 2004 for each status. (orders)
4) Get the maximum payments and their average for each client. (payments)
5) Get the maximum, minimum and average for quantityInStock and buyPrice columns,
where the product line is one of the following: (products)
-Classic Cars
-Trucks and Buses
-Motorcycles
6) Get the product code, orderLineNumber and average of priceEach for every
product and every orderLineNumber where max priceEach is greater than 100. Order
the result set by product in descending order and orderLineNumber in ascending
order. (orderdetails)
7) Get a comma separated list of customerNames for every country. Order the result
set by country in descending order. (customers)
9) Get customer number, if amount is greater than 10000 divide it by 100 for all
payments where checkNumber starts with 'HQ'; (payments)
select customerNumber, checkNumber, amount / CASE WHEN checkNumber LIKE 'HQ%' AND
amount > 10000 THEN 100 ELSE 1 END AS updatedAmount
from payments
where checkNumber like 'HQ%' and amount > 10000;
10) Get city, phone number and addressLine2 from offices. If state is null return
'N/A' for all offices where country is USA (offices)
11) Get all orders where comment exist and status is 'Shipped'. We are interested
just in orders where shippedDate is between 2003-01-25 and 2003-03-20. (orders)
12) For all products calculate how much retailer will earn money by subracting buy
price from MSRP where product code starts with 'S12' OR 'S18' (products)
13) For every product in order details table get product code and calculate
subtotal (quantity * price) for every product order where quantity is greater than
20 and price is less than 120. Round subtotal on two decimal places.
(orderdetails).
14) Get first and last name, reportsTo and job title and email of all employees
whose job title is President or VP Sales or Sales Rep or those who reports to
office code 1. In email replace 'classicmodelcars.com' with 'ibu.edu.ba'. Result
set should be order by job title in descending order. (employees)
15) Get all product lines where productLine contains 'Cars' in its name.
(productlines)
select productLine from productlines
where productLine like '%Cars%'
16) Write a query that will retrieve the product number and the review related to
the product. (product, productreview)
17) Write a query that will combine every product with every possible review
(product, productreview)
18) Get all product numbers and reviews, no matter is there a review for that
product (product, productreview)
19) Get all the reviews and product numbers no matter if that review has a product
or not. (product, productreview)
20) Write a query that will retrieve the product name, product line and the product
line text description (products, productlines) - classicmodels database
21) Write a query which will collect information on the quantity of every product
on each production location. The required data is located in three different
tables:
-Product (contains data about products)
-ProductInventory (contains data about quantity of every product on each location)
-Location (contains data about location of products) It is important to note which
common columns/keys are used to join these tables. (product, productinventory,
location)
22) Modify the previous query so that it returns the total quantity for every
product and every location. Order the result set by total quantity in descending
order.
23) The company manager requires a list of all products, which next to the product
name should contain a name of the unit measure and the product vendor. We are
assigned to extract the data and present it to the manager. (product,
productvendor, vendor, unitmeasure)
select product.Name as ProductName, unitmeasure.Name as UnitMeasureName,
vendor.Name as VendorName from product
inner join productvendor on product.ProductID=productvendor.ProductID
inner join vendor on productvendor.VendorID=vendor.VendorID
inner join unitmeasure on productvendor.UnitMeasureCode=unitmeasure.UnitMeasureCode
24) Get total (each price * quantity) for all orders by status (orders,
orderdetails) - classicmodels
25) Write a query that will return distinct product model IDs and their date of
modification by using the UNION keyword (productmodelproductdescriptionculture)
26) Write a query that will return common product model IDs and their date of
modification by using the INTERSECT keyword (productmodelproductdescriptionculture)