Professional Documents
Culture Documents
**********************************************
(Note: Supply the SQL Server data types when creating the tables. Apply a primary key
to each table.)
Employee
Social_Security_Number
Last_Name
First_Name
Address
City
State
Zip_Code
Telephone_Area_Code
Telephone_Number
Email_Address
Job_Title_Code
Hire_Date
Salary
Job_title
Job_Title_Code
Job_Title
Exempt (holds exempt status which is either 1 or 0)
Minimum_Salary
Maximum_Salary
Using the SQL INSERT statement:
Include all SQL statements (i.e create, insert, etc used to complete each task of your
assignment. Do not include screenshots - rather copy/paste the SQL scripts in the Word
document template attached.
Click the Assignment Files tab to submit your assignment.
Using the database and tables from Lab One, do the following:
Insert ten more records into each table. Verify your inserts by selecting all rows from
each table.
Write SQL queries using BETWEEN, LIKE and UNION as follows:
1. Write a SQL query that joins two tables in the example database and uses BETWEEN
to restrict record selection. (Use salaries to restrict the data.)
2. Write a SQL query that joins two tables in the example database and uses BETWEEN
to restrict record selection. (Use hire dates to restrict the data.)
3. Write a SQL query that joins two tables in the example database and uses LIKE to
restrict record selection. (Use telephone area codes to restrict data.)
4. Write a SQL query that joins two tables in the example database and uses LIKE to
restrict record selection. (Use zip codes to restrict data.)
5. Write a SQL query that uses UNION of the two tables using at least one column from
each table.
Write queries using the SQL GROUP statement to produce the requested reports as
described below. In general, to make grouping meaningful, a function such as COUNT or
SUM is used. In the below tasks, COUNT(*) is the desired function to include in your
SELECT statement along with the requested fields.
6. Display total number of employees for each job title. Columns should include Job_Title
and 'Total Employees'. (Hint: use the "AS clause" to rename a column in the result set.)
7. Display total number of employees for each salary. Columns should include Salary
and 'Total Employees'.
8. Display total number of employees for each salary within each job title. Columns
should include Job Title, Salary, and 'Total Employees'.
9. Display total number of employees for each salary grouped by exempt status.
Columns should include Exempt, Salary, and 'Total Employees'.
Include all SQL statements (i.e create, insert, etc) used to complete each task of your
assignment. Do not include screenshots, rather include the SQL scripts in the Word
document. Label each script with the number of the query and use the order in which
each query is listed in the assignment.
With
a.
b.
c.
d.
SQL, how do you select all the columns from a table named "Persons"?
SELECT *.Persons
SELECT Persons
SELECT * FROM Persons
SELECT [all] FROM Persons
2.
With SQL, how do you select all the records from a table named "Persons" wh
value of
the column "FirstName" is "Peter"?
a.
SELECT * FROM Persons WHERE FirstName LIKE 'Peter'
b.
SELECT [all] FROM Persons WHERE FirstName LIKE 'Peter'
c.
SELECT * FROM Persons WHERE FirstName='Peter'
d.
SELECT [all] FROM Persons WHERE FirstName='Peter'
3.
With SQL, how do you select all the records from a table named "Persons" wh
value of
the column "FirstName" starts with an "a"?
a.
SELECT * FROM Persons WHERE FirstName='%a%'
b.
SELECT * FROM Persons WHERE FirstName LIKE '%a'
c.
SELECT * FROM Persons WHERE FirstName='a'
d.
SELECT * FROM Persons WHERE FirstName LIKE 'a%'
4.
WITH SQL, how do you select all the records from a table named Persons wh
value of
the column age is between 21 and 31?
a.
SELECT * FROM Persons WHERE age BETWEEN 21 AND 31
b.
SELECT * FROM Persons BETWEEN 21 AND 31
c.
SELECT * FROM Persons WHERE age <= 31
5.
WITH SQL, how do you calculate the total number of people from a table
Persons
where the value of the column LastName is Smith?
a.
SELECT TOTAL FROM PersonsWHERE LastName = Smith
b.
SELECT LastName, COUNT(*) FROM PersonsWHERE LastName = SmithGROUP BY La
c.
SELECT COUNT FROM PersonsWHERE LastName = SmithON LastName
Download the attached Word Document Template named "Lastname - Lab 3.doc".
(change Lastname to your last name)
*** ATTENTION! ***
USE THE ATTACHED WORD DOCUMENT TEMPLATE WHEN YOU TURN IN YOUR
ASSIGNMENT
Using the database and tables from Week Three, write queries using the SQL
UPDATE statement.
o
o
o
o
o
Include all SQL statements and results for each task in your assignment post. Do
not include screenshots - rather copy/paste the SQL scripts into the attached
Word document.
produce the report, others use a single query, and still others use multiple queries. I
would estimate that roughly half of the teams I have taught use more than one query. In
all cases, I've seen a lot of variances in how teams choose to implement the report. Let
me provide some suggestions, particularly if you choose to accomplish with one query,
which is definitely possible. First, research the substring or left functions. Either of these
can help you pull the first two digits of the account number as described in the
requirement. If you GROUP BY the first two digits, that is one way of handling the "break
based on the first two digits" requirement mentioned. Secondly, research the COMPUTE
function. You can use this in conjunction with SUM to create your subtotals and total.
6. Report results
Example of using the ROLLUP and SUM functions for subtotals and a grand total: