Task 1 My Database select queries Write a query that uses an aggregate function. selectcount(customerid)fromcustomer; Write a query that retrieves data from at least two of your tables. selectcustomer.*,address.*fromcustomer,addresswhere customer.customerid=address.customerid; Write a query that has a primary and secondary sort. One of the sorts must be in the reverse order. selectcustomer.*,address.*fromcustomer,addresswhere customer.customerid=address.customerid orderbycustomer.firstnamedesc,address.street;
Write a query that implements a wildcard search. select*fromcustomerwherelastnamelike'%n%'; Write a query that uses a mathematical calculation to on two or more columns and uses a column alias on the calculation. selectmax(customerid)-min(customerid)as"Differencebetweenthefirstandlast customerid"fromcustomer;
Adventureworks database queries Using a Join, display the product name and the sales order detail unit price. Sort the data by the unit price. Use table aliases. selectp.name,sod.unitPricefromSalesLT.Productp innerjoinSalesLT.SalesOrderDetailsodonsod.ProductID=p.ProductID groupbyp.name,sod.unitPrice orderbysod.UnitPrice; Using a subquery, display the sales order IDs, order quantity, and unit price for all products that are silver or partially silver in color. selectsod.SalesOrderID,sod.OrderQty,sod.unitPrice,p.name,p.Colorfrom SalesLT.Productp innerjoinsalesLT.SalesOrderDetailsodonsod.ProductID=p.ProductID wherep.productIDIN(selectproductIDfromSalesLT.Productwherecolorlike '%Silver%') orderbysod.UnitPrice;
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Modify the previous subquery so that each order is grouped together as one. selectsod.SalesOrderID,sod.OrderQty,sod.unitPrice,p.name,p.Colorfrom salesLT.Productp innerjoinsalesLT.SalesOrderDetailsodonsod.ProductID=p.ProductID wherep.productIDIN(selectproductIDfromsalesLT.Productwherecolorlike '%Silver%') groupbysod.SalesOrderID,sod.OrderQty,sod.unitPrice,p.name,p.Color orderbysod.UnitPrice; Using a join, display the product name and description. selectp.name,pd.descriptionfromProduction.Productp innerjoinProduction.ProductModelpmonpm.ProductModelID=p.ProductModelID
innerjoinproduction.ProductModelProductDescriptionCulturepmpon pmp.ProductModelID=pm.ProductModelID innerjoinproduction.ProductDescriptionpdon pd.ProductDescriptionID=pmp.ProductDescriptionID; Display the unit price discount for the product with the highest discount. selectTOP1 p.name,sod.UnitPriceDiscountfromSalesLT.Productp innerjoinSalesLT.SalesOrderDetailsodonsod.ProductID=p.ProductID groupbyp.name,sod.UnitPriceDiscount orderbysod.UnitPriceDiscountdesc; Display the customer email addresses sorted alphabetically from Z to A. selectp.EmailAddressfromperson.EmailAddressp orderbyp.EmailAddressdesc;
Display the product names and numbers for all products that started selling July 1, 2002 that stopped being sold June 30, 2003. selectp.name,p.ProductNumberfromSalesLT.Productp innerjoinSalesLT.SalesOrderDetailthonth.ProductID=p.ProductID innerjoinSalesLT.SalesOrderHeadersoonso.SalesOrderID=th.SalesOrderID whereso.OrderDate>='2002-06-01'ANDso.OrderDate<='2003-06-30' groupbyp.name,p.productNumber;