Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Select Businessentityid, Firstname, Middlename, Lastname From Person - Person Where Middlename Like ' (E, B) '

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Solve the following query using AdventureWorks2012 Database:

[Queries are based on following tables:


Person.Person, Sales.SalesOrderHeader, Person.Address,
Sales.SalesOrderDetail, Production.Product, Sales.Customer]

1) Write a query that displays the business entity ID number, first


name, middle name, and last name from the Person.Person table
for only those rows that have E or B stored in the middle name
column.
=========-------
SELECT BusinessEntityID, FirstName, MiddleName, LastName
FROM Person.Person
WHERE MiddleName LIKE '[E,B]';

2) Write a query displaying the order ID, order date, and total due
from the Sales.SalesOrderHeader table. Retrieve only those rows
where the order was placed during the month of September 2005
and the total due exceeded $1,000.
========--------
SELECT SalesOrderID, OrderDate, TotalDue
FROM Sales.SalesOrderHeader
WHERE OrderDate BETWEEN '2005-09-01' AND '2005-09-30'
AND TotalDue > 1000;

3) Explain the difference between the following two queries:

SELECT FirstName
FROM Person.Person
WHERE LastName LIKE 'Ja%es';
SELECT FirstName
FROM Person.Person
WHERE LastName LIKE 'Ja_es';

=======---------
'Ja%es' -> % sign can be replaced by any number of character. Like ‘James’, ‘jammes’,
‘Jamees’ etc.

'Ja_es' -> _ sign can be replaced by only 1 character. Only return ‘James’ but not return
‘jammes’ or ‘Jamees’.

3) Write a query that displays the first 10 characters of the


AddressLine1 column in the Person.Address table.
=======----------
SELECT LEFT(AddressLine1,10) AS Address10
FROM Person.Address;

4) Write a query displaying the first name and last name from the
Person.Person table all in uppercase.
========--------
SELECT UPPER(FirstName) AS FirstName, UPPER(LastName) AS LastName
FROM Person.Person;

5) Write a query that calculates the number of days between the


date an order was placed and the date that it was shipped using
the Sales.SalesOrderHeader table. Include the SalesOrderID,
OrderDate, and ShipDate columns.
=======----------
SELECT SalesOrderID, OrderDate, ShipDate,
DATEDIFF(d,OrderDate,ShipDate) AS NumberOfDays
FROM Sales.SalesOrderHeader;

6) Write a query that displays the count of orders placed by year for
each customer using the Sales.SalesOrderHeader table.
======-------------
SELECT CustomerID, COUNT(*) AS CountOfSales, YEAR(OrderDate) AS OrderYear
FROM Sales.SalesOrderHeader
GROUP BY CustomerID, YEAR(OrderDate);

7) Write a query that creates a sum of the LineTotal in the


Sales.SalesOrderDetail table grouped by the SalesOrderID. Include
only those rows where the sum exceeds 1,000
=====------
SELECT SUM(LineTotal) AS SumOfLineTotal, SalesOrderID
FROM Sales.SalesOrderDetail
GROUP BY SalesOrderID
HAVING SUM(LineTotal) > 1000;

You might also like