Monday, February 23, 2015

#20. Write a SELECT statement that returns these columns from the Orders table

#20.  Write a SELECT statement that returns these columns from the Orders table:
A column that uses the CONVERT function to return the OrderDate column in this format: MM/DD/YYYY. In other words, use two-digit months, days, and years and separate each date component with slashes
A column that uses the CONVERT function to return the OrderDate column with the date, and the hours and minutes on a 12-hour clock with an am/pm indicator
A column that uses the CONVERT function to return the OrderDate column with 2-digit hours, minutes, and seconds on a 24-hour clock. Use leading zeros for all date/time components.


#19. Write a SELECT statement that answers this question: Which customers have ordered more than one product?

#19.  Write a SELECT statement that answers this question: Which customers have ordered more than one product? Return these columns:
The email address from the Customers table
The count of distinct products from the customer’s orders


#18. Write a SELECT statement that returns one row for each customer that has orders with these columns:

#18.  Write a SELECT statement that returns one row for each customer that has orders with these columns:
The EmailAddress column from the Customers table
A count of the number of orders
The total amount for each order (Hint: First, subtract the discount amount from the price. Then, multiply by the quantity.)
Return only those rows where the customer has more than than 1 order.
Sort the result set in descending sequence by the sum of the line item amounts.


#17. Write a SELECT statement that returns one row for each category that has products with these columns:

#17.  Write a SELECT statement that returns one row for each category that has products with these columns:
The CategoryName column from the Categories table
The count of the products in the Products table
The list price of the most expensive product in the Products table
Sort the result set so the category with the most products appears first.


#16. Write a SELECT statement that returns these two columns:

#16.  Write a SELECT statement that returns these two columns:
CategoryName    The CategoryName column from the Categories table
ProductID    The ProductID column from the Products table
Return one row for each category that has never been used. Hint: Use an outer join and only return rows where the ProductID column contains a null value.


#15. Write a SELECT statement that returns the ProductName and ListPrice columns from the Products table.

#15.  Write a SELECT statement that returns the ProductName and ListPrice columns from the Products table.
Return one row for each product that has the same list price as another product. Hint: Use a self-join to check that the ProductID columns aren’t equal but the ListPrice column is equal.
Sort the result set by ProductName.


#14. Write a SELECT statement that joins the Customers, Orders, OrderItems, and Products tables. This statement should return these columns: LastName, FirstName, OrderDate, ProductName, ItemPrice, DiscountAmount, and Quantity.

#14.  Write a SELECT statement that joins the Customers, Orders, OrderItems, and Products tables. This statement should return these columns: LastName, FirstName, OrderDate, ProductName, ItemPrice, DiscountAmount, and Quantity.

Use aliases for the tables.
Sort the final result set by LastName, OrderDate, and ProductName.