Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Let s explore the data through new queries. Q 5 . Let s explore the data through new queries. a ) Write a query that
Lets explore the data through new queries.
Q Lets explore the data through new queries.
a Write a query that shows the product name, product buy price, and MSRP and give each column an appropriate alias.
SELECT productName AS ProductName, buyPrice AS BuyPrice, MSRP AS RetailPrice
FROM products;
b We will now create a calculated attribute. Using the last code Qa and add a new column with the markup for each product see the formula below Give it an appropriate alias.
NOTE: You can create calculated columns by using parenthesis and typing your formula. Refer to the columns as if they were variables in your formula that is selling price would be the MSRP Cost would be the buyPrice
Now we will create filters based on the calculated fields.
c Please add a filter so that we only see products rows with an MSRP higher than and a markup higher than
Note: the alias used for the Markup in the SELECT statement cannot be referenced in the WHERE clause since the WHERE clause runs before the SELECT statement See page of this file to see the order of operations Therefore, you will need to repeat the formula for MARKUP in the where clause
Working with Data in Multiple Tables
For the following questions, we will start using different forms of joins. All of the operations and functions we ran in the first questions can be directly applied to queries composed of multiple tables.
Q Lets compare types of joins EquiJoin vs Inner Join:
a The simplest type of join is an equijoin. Use an equijoin joining with equality in WHERE clause to get shared data between the products and productlines tables. Give an alias to each table so that we can differentiate between them with ease, and keep all columns.
NOTE: These tables are connected through the productLine. Note that your output will return copies of the productLine column as a result of the equijoin from each table
b Replicate the join in Qa using an INNER Join instead of the WHERE clause.
NOTE: These tables are connected through the productLine. Note that your output will return copy of the productLine column since we used an INNER Join rather than an equijoin.
Q Joining or more Tables: It is possible to use these same joins repeatedly to join or more tables. Just keep adding AND functions after the WHERE clause if using an equijoin, or use extra lines with INNER JOIN nexttable ON equality See example below:
a Use an equijoin to join the data from the tables productLines, products and order details. Display the textDescription from the productlines table, the products name and MSRP from the products table, and the order Number and quantity ordered from the orderdetails table.
b Use INNER JOINs to join the data from the tables productLines, products and order details. Display the textDescription from the productlines table, the products name and MSRP from the products table, and the order Number and quantity ordered from the orderdetails table.
Q Outer Joins. Now lets practicing including all data from one of the tables included in our queries. We will repeat the same query for each situation just altering the type of outer query.
For each of the following lettered subsections, join the customer table with the orders table. Remember to:
display all attributes
use aliases for the tables.
Record from which table each attribute is coming from when specifying how the tables will be joined.
a LEFT OUTER Join.
b RIGHT OUTER Join.
Q Now we will create a selfjoin. In our model some employees report to other employees. Create a query that will allow you to see the first and last names of the employees, the employees office code, the code of their manager, their managers first and last name, and job title.
Q Finally, create a view of the query in Q so that we can reuse it later on
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started