Create advanced queries in a database

Assignment Help PL-SQL Programming
Reference no: EM131168048

Advanced SQL Lab - Tutorial

Lab Objective

This lab will allow you to use SQL Server Management Studio to create advanced queries in a database. This software allows you to interact with the database directly. This tool allows a Database Administrator to manage and maintain the database.

Required Materials

• SQL Server 2008 (express or full version).
• AdventureWorksdatabase file or AdventureWorksR2 database file
• Advanced SQL Lab - Tutorial (this document)

Lab Steps

1. Click start, navigate to all programs and select Microsoft SQL Server 2008, and then click on SQL Server Management Studio.

2. Attach the AdventureWorks or AdventureWorks R2 database to SQL Server 2008.

3. You will now create the following queries using Microsoft SQL Server 2008. For each query create a screenshot to show your results. Make sure you use the correct version of each query for your database.

4. Query 1- for AdventureWorks
****note error-have group function and row data in
**** same Select clause-requires Group By
select min(Rate), EmployeeID
from HumanResources.EmployeePayHistory
group by EmployeeID

Query 1- for AdventureWorksR2
****note error-have group function and row data in
**** same Select clause-requires Group By
select min(Rate), ID
fromHumanResources.EmployeePayHistory
group by BusinessEntityID

Insert screenshot below:

5. Query 2-for AdventureWorks

*** SubQuery! Only have to run one query...
select EmployeeID, Rate
from HumanResources.EmployeePayHistory
where Rate = (Select min(Rate) from HumanResources.EmployeePayHistory)

Query 2- for AdventureWorks R2
*** SubQuery! Only have to run one query...
selectBusinessEntityID, Rate
fromHumanResources.EmployeePayHistory
where Rate = (Select min(Rate) from HumanResources.EmployeePayHistory)

Insert screenshot below:

6. Query 3- for either database

****execute query with min, max in place of avg
select avg(Rate)
from HumanResources.EmployeePayHistory

Insert screenshot below:

7. Query 4- for AdventureWorks

**** only display first 3 from results list
***enter ASC to see top 3 lowest paid employees!
select top 3 Rate, EmployeeID
from HumanResources.EmployeePayHistory
Order by Rate Desc

Query 4-for AdventureWorksR2
**** only display first 3 from results list
***enter ASC to see top 3 lowest paid employees!
select top 3 Rate, BusinessEntityID
fromHumanResources.EmployeePayHistory
Order by Rate Desc

Insert screenshot below:

8. Query 5-for AdventureWorks

****Note Alias. INNER JOIN returns only those rows that have matches in ***both tables.
SELECT Person.Contact.FirstName + ' ' + Person.Contact.LastName AS [Full Name] FROM Person.Contact INNER JOIN HumanResources.Employee ON Person.Contact.ContactID = HumanResources.Employee.ContactID

Query 5- for AdventureWorksR2
****Note Alias. INNER JOIN returns only those rows that have matches in ***both tables.
SELECT Person.Person.FirstName + ' ' + Person.Person.LastName AS [Full Name] FROM Person.Person INNER JOIN HumanResources.Employee
ON Person.Person.BusinessEntityID = HumanResources.Employee.BusinessEntityID

Insert screenshot below:

9. Query 6-for AdventureWorks
***When need data from 3 tables, need 2 sets of join conditions. Need to ***join first two tables and join result to third table.
SELECT HumanResources.Employee.EmployeeID, Person.Contact.FirstName, Person.Contact.LastName, Person.Contact.Phone, HumanResources.EmployeePayHistory.Rate FROM Person.Contact INNER JOIN HumanResources.Employee ON Person.Contact.ContactID = HumanResources.Employee.ContactID INNER JOIN HumanResources.EmployeePayHistory ON HumanResources.Employee.EmployeeID = HumanResources.EmployeePayHistory.EmployeeID WHERE HumanResources.EmployeePayHistory.Rate > 50 ORDER BY HumanResources.EmployeePayHistory.Rate DESC

Query 6-for AdventureWorksR2
***When need data from 3 tables, need 2 sets of join conditions. Need to ***join first two tables and join result to third table.
SELECTHumanResources.Employee.BusinessEntityID, Person.Person.FirstName, Person.Person.LastName, HumanResources.EmployeePayHistory.Rate
FROM Person.Person
INNER JOIN HumanResources.Employee
ON Person.Person.BusinessEntityID= HumanResources.Employee.BusinessEntityID
INNER JOIN HumanResources.EmployeePayHistory ON HumanResources.Employee.BusinessEntityID = HumanResources.EmployeePayHistory.BusinessEntityID WHERE HumanResources.EmployeePayHistory.Rate> 50 ORDER BY HumanResources.EmployeePayHistory.Rate DESC

Attachment:- SQL-Assignment.rar

Reference no: EM131168048

Questions Cloud

Construct an estimator of the mean and median : You are interested in purchasing a home in Santa Barbara. To determine if it is a good time to buy, you collect the selling prices of all homes in the city over the past three years, giving you 497 observations. Let us denote observation 't' as  P..
Describe such circumstances whether true or false : The following two sentences were devised by the logician Saul Kripke. While not intrinsically paradoxical, they could be paradoxical under certain circumstances. Describe such circumstances.
Create a table that includes a rotating schedule : Create a table that includes a rotating schedule for the 12 months of security testing. Include columns that identify time estimations for each test listed.
Confidence interval estimate of the population mean : In Calculating a 95% confidence interval estimate of the population mean based on your sample of 100 which yielded a sample mean of 110.27 and a sample standard of 28.95, What "t" value will you use in your equation?
Create advanced queries in a database : This lab will allow you to use SQL Server Management Studio to create advanced queries in a database. This software allows you to interact with the database directly.
Which presidential and parliamentary democracy differ : Presidential democracies lack party control while parliamentary democracies have strong party control. Now that I have described the four keys differences, explain what some of them mean.
Standard deviation greater : Based on the sample results, the researcher concludes that the pulse rates of men have a standard deviation greater than 10 beats per minutes. Use a 0.05 significance level to test the researcher's claim.
Explain how it leads to a contradiction : Let n be "the smallest integer not describable in fewer than 12 English words." (Note that the total number of strings consisting of 11 or fewer English words is finite.)
Different model forms : Total marketing effort is a term used to describe the critical decision factors that affect demand: price, advertising, distribution, and product quality. Let the variable x represent total marketing effort. A typical model that is used to predict..

Reviews

Write a Review

PL-SQL Programming Questions & Answers

  Write sql statement to create stored procedure

Write SQL statement which creates stored procedure with one int input parameter. The stored procedure selects the supplierId field and the total of all Count field values for each group of supplierId's from the Part table.

  Run the lab_03_01.sql script

Run the lab_03_01.sql script in the attached file to create the SAL_HISTORY table. Display the structure of the SAL_HISTORY table.

  Write a perl subroutine for temperature conversion

Write a perl subroutine for temperature conversion named 'convert_temp'. It should be able to handle both Fahrenheit to Celsius conversions as well as Celsius to Fahrenheit conversions.

  Problems in a project

1. First read and analyze each problem; then implement both problems in a project called HW3. 2. For each exercise, insert comments on ID, Name, and HW#.

  Build cross-cultural awareness

Working across cultures can be enriching and meaningful. Colleagues can build cross-cultural awareness by engaging with people who are similar to and yet different from them. At the same time, working across cultures also has its challenges.

  Write a query to display the starting salary

Write a query to display the starting salary for each employee. The starting salary would be the entry in the salary history with the oldest salary start date for each employee. Sort the output by employee number.

  Which is better to use, a sub query or a join

Please include example of each to support your reasoning. Also, please include references.

  Canned messages data structure

Examples of canned messages stored in the canned messages data structure (you can store as many canned messages as you would like):

  Create and populate the database system using sql server

Global Car Club (GCC) is a small individually owned club which loans cars to its members. GCC first formed in 2009; has over more than 100 good mixes of members and counting.

  Write the sql code to perform the tasks

Write the SQL code to perform the tasks requested in each problem. Define a new containing the product number, name, price, and quantity on hand along with the number of orders in which the product appears.

  Querries related to sql programming

Create a parameter query based on the Customer tablethat prompts for customers in a specific state. Do not just make a select query. A parameter is different. Display the CustomerNum, CustomerName, City, and State fields.

  Write a select statement that returns four columns

Write a SELECT statement that returns four columns from the Products table: ProductCode, ProductName, ListPrice, and DiscountPercent. Then, run this statement to make sure it works correctly.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd