Question

In: Computer Science

Consider the following three tables, primary and foreign keys. Table Name        SalesPeople Attribute Name                  &nbsp

Consider the following three tables, primary and foreign keys.

Table Name        SalesPeople

Attribute Name                                Type                                      Key Type

EmployeeNumber             Number                               Primary Key

Name                                   Character

JobTitle                                  Character           

Address                                 Character

PhoneNumber                     Character

YearsInPosition                             Number

Table Name        ProductDescription

Attribute Name                                Type                                      Key Type

                ProductNumber                Number                               Primary Key

                ProductName                  Character           

                ProductPrice                   Number

Table Name        SalesOrder

Attribute Name                                Type                                      Key Type

                SalesOrderNumber        Number                               Primary Key

                ProductNumber               Number                               Foreign Key

                EmployeeNumber           Number                               Foreign Key

                SalesOrderDate                Date

Assume that you draw up a new sales order for each product sold.

Develop the following queries in SQL:

a.       All the Sales People with less than four years in position.  

b.      All the Product Names sold on April 4th.  

c.       All the Products sold by Sales People less than 3 years in the position.  

Solutions

Expert Solution

SOLUTION a:

SELECT * FROM SalesPeople WHERE yearsInPosition<4

EXPLANATION:

STEP 1: We need to check for the yearsInPosition is greater than 4 years or not and then we need to project them

OUTPUT:

SOLUTION b:

SELECT ProductName FROM SalesOrder so,ProductDescription pd
WHERE so.ProductNumber==pd.ProductNumber AND SalesOrderDate LIKE ("%04-04")

EXPLANATION:

STEP 1: We need to join the two tables salesorder and productdescription by using the productnumber

STEP 2: Then we need to check for the order date as like april 4 th

STEP 3: Project the ProductName

OUTPUT:

SOLUTION c:

SELECT ProductName,sp.name FROM SalesOrder so,SalesPeople sp,ProductDescription pd
WHERE so.EmployeeNumber ==sp.EmployeeNumber AND yearsInPosition<3 AND pd.ProductNumber==so.ProductNumber

EXPLANATION:

STEP 1: We need to join SalesOrder,SalesPeople so that we will get all the details of sales and sales person

STEP 2: Filter the yearsInposition condition less than 3

STEP 3: Join the previous result with the ProductDescription table to get the products table using productnumber

OUTPUT AND CODE:


Related Solutions

Consider the following relational schema about a University (the primary keys are underlined and foreign keys...
Consider the following relational schema about a University (the primary keys are underlined and foreign keys are italic) STUDENT(StudentID, name, major, year, age) CLASS(ClassName, meetsAt, room, LecturerID) ENROLLED(StudentID, ClassName, mark) LECTURER(LecturerID, name, DepartmentID) DEPARTMENT(DepartmentID, name) Write the SQL statements for the following query: B1. Find the age of the oldest student. B2. Find the ID’s of lecturers whose name begins with “K” \ B3. Find the age of the youngest student who is enrolled in Mechatronics. B4. Find the age...
Please create the following tables for a tool rental database with appropriate primary keys & foreign...
Please create the following tables for a tool rental database with appropriate primary keys & foreign keys. Assumptions: 1. Each tool belongs to a category. 2. Each category may have a parent category but the parent category should not have a parent category (so at most two levels). E.g., a Tool A belongs to the electric mower, and electric mowers belong to mowers. Mower has no parent category. 3. Each tool can be rented at different time units. The typical...
Problem 1. Please create the following tables for a tool rental database with appropriate primary keys...
Problem 1. Please create the following tables for a tool rental database with appropriate primary keys & foreign keys. [30 points] Assumptions: Each tool belongs to a category. Each category may have a parent category but the parent category should not have parent category (so at most two levels). E.g., a Tool A belongs to electric mower, and electric mower belongs to mower. Mower has no parent category. Each tool can be rented at different time units. The typical time...
1. Consider the following relations. The primary keys are underlined. All attributes are of type string...
1. Consider the following relations. The primary keys are underlined. All attributes are of type string if not indicated otherwise.  Student(s_ID, s_name, s_degree: integer, advisorID, d_ID)  Lecture(l_ID, l_name,l_degree: integer, p_ID, d_ID)  Register(s_ID,l_ID,score: integer, Semester)  Professor(p_ID,p_name, d_ID)  Department(d_ID, d_name, address) a. Find the names of professors who have taught in every semester. b. List the names of lectures that the CISE department offers but that are taught by a professor whose department is not CISE. c....
Create a table in SQL with foreign key reference: 1.Create the three tables without any columns...
Create a table in SQL with foreign key reference: 1.Create the three tables without any columns 2.Alter the tables to add the columns 3.Alter the tables to create the primary and foreign keys
SQL ONLY. WRITE CLEAR AND CORRECT ANSWERS. Consider the following relations (PRIMARY KEYS ARE WRITTEN IN...
SQL ONLY. WRITE CLEAR AND CORRECT ANSWERS. Consider the following relations (PRIMARY KEYS ARE WRITTEN IN BOLD) departments (dept_no, dept_name) dept_emp (emp_no, dept_no, from_date, to_date) dept_manager (dept_no, emp_no, from_date, to_date) employees (emp_no, birth_date, first_name, last_name, gender, hire_date) salaries (emp_no, salary, from_date, to_date) titles(emp_no, title, from_date, to_date) Write the following queries in SQL. No duplicates should be printed in any of the answers. List all the titles for which there is at least one employee having the title. Find the current...
SQL ONLY. WRITE CLEAR AND SIMPLE ANSWERS. Consider the following relations (PRIMARY KEYS ARE WRITTEN IN...
SQL ONLY. WRITE CLEAR AND SIMPLE ANSWERS. Consider the following relations (PRIMARY KEYS ARE WRITTEN IN BOLD) departments (dept_no, dept_name) dept_emp (emp_no, dept_no, from_date, to_date) dept_manager (dept_no, emp_no, from_date, to_date) employees (emp_no, birth_date, first_name, last_name, gender, hire_date) salaries (emp_no, salary, from_date, to_date) titles(emp_no, title, from_date, to_date) Write the following queries in SQL. No duplicates should be printed in any of the answers. List all the titles for which there is at least one employee having the title. Find the current...
Create table, create primary and foreign key constraints. Create index on the table to satisfy a...
Create table, create primary and foreign key constraints. Create index on the table to satisfy a query with aggregate functions.
Identify whether each attribute in the following table is an advantage or disadvantage of sharing a...
Identify whether each attribute in the following table is an advantage or disadvantage of sharing a currency across country boundaries. Attribute Advantage Disadvantage Price stability Limited scope for fiscal policy Lower transaction costs Speculative attacks during currency transition Protection from monetary disturbances and speculation Which of the following are reasons the European Union is considered   currency area? Check all that apply. Labor immobility Limited use of fiscal policy Low economic efficiency gains No legal or cultural barriers to labor mobility...
Consider the following table definitions create table node( node_id integer primary key, node_color varchar(10)); create table...
Consider the following table definitions create table node( node_id integer primary key, node_color varchar(10)); create table edge( edge_id integer primary key, origin_id integer, destination_id integer, foreign key (origin_id) references node(node_id), foreign key (destination_id) references node(node_id)); What is the result of the following query? select node_id, node_color, destination_id from node, edge; An inner join of the tables node and edge that lists origin node_id and node_color together with the node_id of the destination node for all those nodes that have outgoing...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT