MADE BY-KUSHAL
CLASS-12THC1
ROLL NO-04
Question: Write an SQL query to fetch the EmpId and FullName of
all the employees working under the Manager with id – ‘986’.
Query:
SELECT EmpId, FullName
2FROM EmployeeDetails
3WHERE ManagerId = 986;
Output:
EmpId FullName
101 John Doe
102 Jane Smith
103 Alice Johnson
Question: Write an SQL query to fetch the different projects available
from the EmployeeSalary table.
Query:
SELECT DISTINCT Project
2FROM EmployeeSalary;
Output:
P1
P2
P3
Question: Write an SQL query to fetch the count of employees
working in project ‘P1’.
Query:
SELECT COUNT(*)
2FROM EmployeeSalary
3WHERE Project = 'P1';
Output:
COUNT(*)
5
Question: Write an SQL query to find the maximum, minimum,
and average salary of the employees.
Query:
SELECT MAX(Salary) AS MaxSalary,
2 MIN(Salary) AS MinSalary,
3 AVG(Salary) AS AverageSalary
4FROM EmployeeSalary;
Output:
MaxSalary MinSalary AverageSalary
120000 30000 65000
Question: Write an SQL query to fetch those employees who live in
Toronto and work under the manager with ManagerId – 321.
sql
Query:
SELECT EmpId, City, ManagerId
2FROM EmployeeDetails
3WHERE City = 'Toronto' AND ManagerId = 321;
Output:
EmpId City ManagerId
EmpId City ManagerId
201 Toronto 321
202 Toronto 321
Question: Write an SQL query to fetch all the employees who are not
working on any project.
sql
Query:
SELECT EmpId
2FROM EmployeeSalary
3WHERE Project IS NULL;
Output:
EmpId
301
302
Question: Write an SQL query to find the employee id whose salary
lies in the range of 9000 and 15000.
Query:
SELECT EmpId, Salary
2FROM EmployeeSalary
3WHERE Salary BETWEEN 9000 AND 15000;
Output:
EmpId Salary
401 12000
402 11000
Question: Write an SQL query to print details of the Students whose
FIRST_NAME ends with 'a'.
Query:
SELECT *
2FROM Student
3WHERE FIRST_NAME LIKE '%a';
Output:
StudentId FIRST_NAME LAST_NAME
501 Maria Johnson
502 Ava Smith
Question: Write an SQL query to print details of the Students whose
GPA lies between 9.00 and 9.99.
sql
Query:
SELECT *
2FROM Student
3WHERE GPA BETWEEN 9.00 AND 9.99;
Output:
StudentId FIRST_NAME GPA
601 John 9.5
602 Emily 9.2
Question: Write an SQL query to print details of the Students with
the FIRST_NAME as 'Prem' and 'Shivansh'.
Query:
SELECT *
2FROM Student
3WHERE FIRST_NAME IN ('Prem', 'Shivansh');
Output:
StudentId FIRST_NAME LAST_NAME
701 Prem Kumar
702 Shivansh Sharma
Question: Write an SQL query to fetch the EmpId and FullName of
employees whose salary is greater than 80000.
Query:
SELECT EmpId, FullName
2FROM EmployeeDetails
3WHERE Salary > 80000;
Output:
EmpId FullName
101 John Doe
104 Sarah Connor
Question: Write an SQL query to fetch the EmpId and FullName of
employees who work in the 'IT' department and have a salary greater
than 60000.
Query:
SELECT EmpId, FullName
2FROM EmployeeDetails
3WHERE Department = 'IT' AND Salary > 60000;
Output:
EmpId FullName
102 Jane Smith
103 Alice Johnson
Question: Write an SQL query to fetch the EmpId and FullName of
employees, ordered by their salary in descending order.
Query:
SELECT EmpId, FullName
2FROM EmployeeDetails
3ORDER BY Salary DESC;
Output:
EmpId FullName
101 John Doe
104 Sarah Connor
102 Jane Smith
Question: Write an SQL query to count the number of employees in each
department.
Query:
SELECT Department, COUNT(*) AS EmployeeCount
2FROM EmployeeDetails
3GROUP BY Department;
Output:
Department EmployeeCount
IT 3
HR 2
Finance 2
Question: Write an SQL query to fetch the details of employees whose
last name is 'Smith'.
Query:
SELECT *
2FROM EmployeeDetails
3WHERE LastName = 'Smith';
Output:
EmpId FullName Department Salary
102 Jane Smith IT 70000
105 Bob Smith HR 50000
Q: Write a function to reverse a given
string.
Code:
def reverse_string(s):
2 return s[::-1]
3
4# Example usage
5print(reverse_string("hello")) # Output:
"olleh"
Q: Write a function to check if a string is
a palindrome.
Code:
def is_palindrome(s):
2 return s == s[::-1]
3
4# Example usage
5print(is_palindrome("radar")) # Output:
True
6print(is_palindrome("hello")) # Output:
False
Q: Write a function to generate the first n
Fibonacci numbers.
python
Code:
def fibonacci(n):
2 fib_sequence = [0, 1]
3 for i in range(2, n):
4 fib_sequence.append(fib_sequence[-
1] + fib_sequence[-2])
5 return fib_sequence[:n]
6
7# Example usage
8print(fibonacci(10)) # Output: [0, 1, 1, 2,
3, 5, 8, 13, 21, 34]
Q: Write a function to calculate the
factorial of a number.
Code:
def factorial(n):
2 if n == 0:
3 return 1
4 return n * factorial(n - 1)
5
6# Example usage
7print(factorial(5)) # Output: 120
Q: Write a function to check if a number
is prime.
Code:
def is_prime(n):
2 if n <= 1:
3 return False
4 for i in range(2, int(n**0.5) + 1):
5 if n % i == 0:
6 return False
7 return True
8
9# Example usage
10print(is_prime(11)) # Output: True
11print(is_prime(4)) # Output: False
Q: Write a function to count the number of
vowels in a string.
Code:
def count_vowels(s):
2 vowels = 'aeiouAEIOU'
3 return sum(1 for char in s if char in
vowels)
4
5# Example usage
6print(count_vowels("hello world")) #
Output: 3
Q: Write a function to merge two
dictionaries.
Code:
def merge_dicts(dict1, dict2):
2 return {**dict1, **dict2}
3
4# Example usage
5dict1 = {'a': 1, 'b': 2}
6dict2 = {'b': 3, 'c': 4}
7print(merge_dicts(dict1, dict2)) #
Output: {'a': 1, 'b': 3, 'c': 4}
Q: Write a function to find the maximum
element in a list.
Code:
def find_max(lst):
2 return max(lst)
3
4# Example usage
5print(find_max([1, 2, 3, 4, 5])) #
Output: 5
Q: Write a function to remove duplicates
from a list.
Code:
def remove_duplicates(lst):
2 return list(set(lst))
3
4# Example usage
5print(remove_duplicates([1, 2, 2, 3, 4, 4,
5])) # Output: [1, 2, 3, 4, 5]
Q: Write a function to sort a list of tuples
by the second element.
Code:
def sort_tuples(lst):
2 return sorted(lst, key=lambda x: x[1])
3
4# Example usage
5tuples_list = [(1, 3), (2, 1), (3, 2)]
6print(sort_tuples(tuples_list)) # Output:
[(2, 1), (3, 2), (1, 3)]
Q: Create a line plot to visualize the sine and cosine
functions on the same graph.
Code:
import matplotlib.pyplot as plt
2import numpy as np
3
4# Data
5x = np.linspace(0, 2 * np.pi, 100)
6y1 = np.sin(x)
7y2 = np.cos(x)
8
9# Plot
10plt.plot(x, y1, label='Sine', color='blue')
11plt.plot(x, y2, label='Cosine', color='orange')
12plt.title('Sine and Cosine Functions')
13plt.xlabel('X-axis (radians)')
14plt.ylabel('Y-axis')
15plt.legend()
16plt.grid()
17plt.show()
Q: Create a box plot to show the distribution of
scores from three different classes.
Code:
import matplotlib.pyplot as plt
2import numpy as np
3
4# Data
5class1 = np.random.normal(70, 10, 100)
6class2 = np.random.normal(80, 15, 100)
7class3 = np.random.normal(75, 20, 100)
8
9data = [class1, class2, class3]
10
11# Plot
12plt.boxplot(data, labels=['Class 1', 'Class 2',
'Class 3'])
13plt.title('Box Plot of Scores from Three Classes')
14plt.ylabel('Scores')
15plt.grid()
16plt.show()
Q: Create an area plot to visualize the cumulative
sales of a product over several months.
Code:
import matplotlib.pyplot as plt
2import numpy as np
3
4# Data
5months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
6sales = [100, 200, 300, 400, 500, 600]
7
8# Plot
9plt.fill_between(months, sales, color='skyblue',
alpha=0.4)
10plt.plot(months, sales, color='Slateblue',
alpha=0.6, linewidth=2)
11plt.title('Cumulative Sales Over Months')
12plt.xlabel('Months')
13plt.ylabel('Sales')
14plt.grid()
15plt.show()
Q: Create a bar chart to show the sales of
different products.
Code:
mport matplotlib.pyplot as plt
2
3# Data
4products = ['Product A', 'Product B',
'Product C', 'Product D']
5sales = [150, 200, 300, 250]
6
7# Plot
8plt.bar(products, sales, color='green')
9plt.title('Sales of Products')
10plt.xlabel('Products')
11plt.ylabel('Sales')
12plt.show()
Q: Create a simple line plot of a mathematical
function, such as (y = x^2).
Code:
import matplotlib.pyplot as plt
2import numpy as np
3
4# Data
5x = np.linspace(-10, 10, 100)
6y = x ** 2
7
8# Plot
9plt.plot(x, y, label='y = x^2', color='blue')
10plt.title('Line Plot of y = x^2')
11plt.xlabel('x-axis')
12plt.ylabel('y-axis')
13plt.legend()
14plt.grid()
15plt.show()