SQL: Start with the Employee table used in Lab 4.   CREATE TABLE Employee ( EMPLOYEE_ID        INT NOT NULL, FIRST_NAME        CHAR(20), LAST_NAME        CHAR(20), JOB_LEVEL        INT, SALARY                BIGINT, COMMISSION_PCT INT, CONSTRAINT PKEmployeeID PRIMARY KEY (EMPLOYEE_ID) );   INSERT INTO Employee VALUES (100,'Steven','King',1,50000,10), (101,'Neena','Kochhar',1,50000,10), (102,'Lex','De Haan',2,60000 ,15), (103,'Alexander','Hunold',2,60000,15), (104,'Bruce','Ernst',3,70000,25), (105,'Johann','Ernst',4,75000,30);   Create another table.   CREATE TABLE NumEmployeesByLastName ( LastName                CHAR(20), NumEmployees        INT );   a. Write a query to initialize the NumEmployeesByLastName table by inserting one row for each last name already in the Employee table, and having the accurate count of the number of employees having that last name. Assume that there are no null values in the Employee table.   After your query, if you execute the following query, you would get the following output.   SELECT * FROM NumEmployeesByLastName;   LastName NumEmployees King 1 Kochhar 1 De Haan 1 Hunold 1 Ernst 2

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

SQL:

Start with the Employee table used in Lab 4.

 

CREATE TABLE Employee

(

EMPLOYEE_ID        INT NOT NULL,

FIRST_NAME        CHAR(20),

LAST_NAME        CHAR(20),

JOB_LEVEL        INT,

SALARY                BIGINT,

COMMISSION_PCT INT,

CONSTRAINT PKEmployeeID PRIMARY KEY (EMPLOYEE_ID)

);

 

INSERT INTO Employee

VALUES

(100,'Steven','King',1,50000,10),

(101,'Neena','Kochhar',1,50000,10),

(102,'Lex','De Haan',2,60000 ,15),

(103,'Alexander','Hunold',2,60000,15),

(104,'Bruce','Ernst',3,70000,25),

(105,'Johann','Ernst',4,75000,30);

 

Create another table.

 

CREATE TABLE NumEmployeesByLastName

(

LastName                CHAR(20),

NumEmployees        INT

);

 

a. Write a query to initialize the NumEmployeesByLastName table by inserting one row for each last name already in the Employee table, and having the accurate count of the number of employees having that last name. Assume that there are no null values in the Employee table.

 

After your query, if you execute the following query, you would get the following output.

 

SELECT * FROM NumEmployeesByLastName;

 

LastName

NumEmployees

King

1

Kochhar

1

De Haan

1

Hunold

1

Ernst

2

 

 

b. Write a trigger to update NumEmployeesByLastName whenever a new record is inserted into the Employee table.

After your trigger is created, if you execute the following queries, you will get the following table.

SET SQL_SAFE_UPDATES = 0;

INSERT INTO Employee VALUES (200, 'Ankit', 'Pattan', 3, 70000, 25);

INSERT INTO Employee VALUES (201, 'Amy', 'King', 3, 70000, 25);

SELECT * FROM NumEmployeesByLastName;

 

LastName

NumEmployees

King

2

Kochhar

1

De Haan

1

Hunold

1

Ernst

2

Pattan

1

 

 

c. Create a procedure FindCommissionDiff that takes 2 employee ids as input. The procedure returns the difference between the commission of the two employees as output. The output parameter is set to the commission of employee1 - the commission of employee2.

After you define the procedure, if you execute these queries, you get the output -5.

CALL FindCommissionDiff(101, 102, @df);

SELECT @df;

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY