0% found this document useful (0 votes)
4 views4 pages

SQL Queries for Employee Management

The document contains SQL queries for various scenarios related to employee management, including inserting a new employee, selecting top earners, counting employees by department, and updating department assignments. Additionally, it includes mathematical problems related to sales and profit calculations, along with programming concepts such as if-else statements and for loops. Each section provides clear examples and explanations for the tasks at hand.

Uploaded by

Ashish Eradi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

SQL Queries for Employee Management

The document contains SQL queries for various scenarios related to employee management, including inserting a new employee, selecting top earners, counting employees by department, and updating department assignments. Additionally, it includes mathematical problems related to sales and profit calculations, along with programming concepts such as if-else statements and for loops. Each section provides clear examples and explanations for the tasks at hand.

Uploaded by

Ashish Eradi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SECTION-1

1Q) Scenario 1: A new employee, "Sarah," is joining the company. Write an SQL query to insert a new record for Sarah
into the "EmployeeDetails" table with her details. Make sure to generate a unique EmployeeID for her.

1A) Assuming a unique EmployeeID is generated automatically, you can use the following query to insert a new
employee record for Sarah.

SQL Code

INSERT INTO EmployeeDetails (FirstName, LastName, Salary, JoiningDate, DepartmentID)

VALUES ('Sarah', 'Williams', 85000, '2023-11-02', 4);

2Q) Scenario 2: The company wants a report of its top earners, showing the EmployeeID, FirstName, LastName,
Salary, and DepartmentName. Write an SQL query to select the details of the top 5 earners along with their
department names.

2A) -- You can use the following query to select the top 5 earners and their department names.

SQL Code

SELECT [Link], [Link], [Link], [Link], [Link]

FROM EmployeeDetails E

INNER JOIN Departments D ON [Link] = [Link]

ORDER BY [Link] DESC

LIMIT 5;

3Q) Scenario 3: HR wants to know how many employees are in each department. Write an SQL query to select the
"DepartmentName" and the count of employees in each department. Use an inner join between the
"EmployeeDetails" and "Departments" tables.

3A) -- You can use the following query to select the DepartmentName and the count of employees in each
department.

SQL Code

SELECT [Link], COUNT([Link]) AS EmployeeCount

FROM Departments D

LEFT JOIN EmployeeDetails E ON [Link] = [Link]

GROUP BY [Link];
4Q) Scenario 4: The company is expanding and is creating a new department named "Research and Development."
Write an SQL query to insert a new department with the appropriate DepartmentID and DepartmentName into the
"Departments" table.

4A) -- You can use the following query to insert a new department named "Research and Development" with an
appropriate DepartmentID.

SQL code

INSERT INTO Departments (DepartmentID, DepartmentName)

VALUES (6, 'Research and Development');

5Q) Scenario 5: The company has recently created a new department called "Quality Assurance" (DepartmentID 6).
They want to assign a few employees to this new department. Write an SQL query to update the "DepartmentID" in
the "EmployeeDetails" table for a few employees (EmployeeID 11, 18, 20, 3) and assign them to the "Quality
Assurance" department (DepartmentID 6)

5A) -- You can use the following query to update the DepartmentID for selected employees and assign them to the
"Quality Assurance" department (DepartmentID 6).

SQL code

UPDATE EmployeeDetails

SET DepartmentID = 6

WHERE EmployeeID IN (11, 18, 20, 3);

SECTION-2
1. A man has Rs.480 in the denominations of one-rupee notes, five-rupee notes and ten-rupee notes. The number of
notes of each denomination is equal. What is the total number of notes that he has ?

A.45 B.60 C.75 D.90

1A) D.90

2. A grocer has a sale of Rs. 6435, Rs. 6927, Rs. 6855, Rs. 7230 and Rs. 6562 for 5 consecutive months. How much sale
must he have in the sixth month so that he gets an average sale of Rs. 6500?

[Link]. 4991 [Link]. 5991 [Link]. 6001 [Link]. 6991

2A) [Link] 5991

3. A company's revenue is $500,000, and its expenses are $350,000. Calculate the company's profit.

A) $500,000 B) $350,000 C) $150,000 D) $200,000

3A) C) $150,000
SECTION-3
1Q. Explain the purpose of if-else statements in programming. How do they enable decision-making in code? Provide
an example scenario where an if-else statement would be useful.

1A) Purpose of if-else statements in programming: If-else statements in programming are used to enable decision-
making within the code. They allow the program to execute different sets of instructions based on a specific condition
or set of conditions. The primary purpose of if-else statements is to control the flow of the program by determining
which block of code to execute. Here's how they work:

• An if statement evaluates a condition. If the condition is true, the code inside the if block is executed. If the
condition is false, the code inside the if block is skipped.

• An else statement is often used in conjunction with an if statement. If the condition in the if statement is
false, the code inside the else block is executed.

Example : Suppose you are writing a program to check whether a person is eligible to vote in an election. The
condition for eligibility could be the age of the person. Here's how an if-else statement can be used

Code:

age = 18

if age >= 18:

print("You are eligible to vote.")

else:

print("You are not eligible to vote.")

In this scenario, the if statement checks if the person's age is greater than or equal to 18. If it's true, the program
informs the person that they are eligible to vote. If it's false, the else block is executed, and the person is told that
they are not eligible to vote.

2Q. Describe the purpose of a for loop in programming. Provide an example of a situation

where a for loop would be useful and explain how it works.

2A) Purpose of a for loop in programming: A for loop is a control structure used in programming to execute a specific
block of code repeatedly a predetermined number of times or over a specified range. It is particularly useful when
you need to perform repetitive tasks or iterate over a collection of items. Here's how it works:

• A for loop consists of three parts: initialization, condition, and iteration.

• The loop initializes a variable, checks a condition, and increments or decrements the variable with each
iteration.

• As long as the condition is true, the code inside the loop is executed.

Example : Consider a situation where you want to print numbers from 1 to 10. A for loop can be used to achieve this

Code

for i in range(1, 11):

print(i)

In this example, the for loop initializes the variable i to 1, checks if i is less than or equal to 10, and increments i by 1
in each iteration. The loop will run ten times, and the numbers from 1 to 10 will be printed to the console. The for
loop makes it easy to perform repetitive tasks without duplicating code.

You might also like