In: Computer Science
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.
Answer:
a.All the Sales People with less than four years in the position.
Select * from SalesPeople where YearsInPosition <
4;
/* This command will list down all the Sales People with less than
four years in position*/
b.All the Product Names sold on April 4th.
Select so.SalesOrderDate, pd.ProductName from SalesOrder
so
join ProductDescription pd on pd.ProductNumber =
so.ProductNumber
where so.SalesOrderDate like '04/04%';
/* This command will list down all the Product Names sold on April
4th */
c.All the Products sold by Sales People less than 3 years in the position.
Select so.ProductNumber, sp.Name, so.SalesOrderNumber,
sp.YearsInPosition from SalesOrder so
join SalesPeople sp on sp.EmployeeNumber = so.EmployeeNumber
where sp.YearsInPosition < 3 order by sp.Name;
/* This command will list down all the Products sold by Sales
People less than 3 years in the position.*/
Let me know in case if you have any doubts. Thanks and All the best.