Answer Key For SET-1 TO 3
Answer Key For SET-1 TO 3
import pandas as pd
cricketers = pd.DataFrame(data)
(d) Create a bar chart between cricketer’s name and their salaries.
USE Board2023;
(b) Write SQL commands to insert the records in the employees table.
INSERT INTO employees VALUES (1, 'Ram', 30, 'Manager', 'Delhi');
INSERT INTO employees VALUES (2, 'Karan', 19, 'Sales', 'Chandigarh');
INSERT INTO employees VALUES (3, 'Shyam', 30, 'Sales', 'Delhi');
INSERT INTO employees VALUES (4, 'Anu', 38, 'Manager', 'Goa');
INSERT INTO employees VALUES (5, 'Rahul', 24, 'Office', 'Goa');
(c) Write a query to display the youngest and oldest age of employees.
SELECT MIN(Age) AS Youngest, MAX(Age) AS Oldest FROM employees;
(d) Display name, age, and department of all the employees of Delhi, arranged in
ascending order of age.
SELECT Name, Age, Department FROM employees
WHERE City = 'Delhi'
ORDER BY Age ASC;
(f) Display the records of all employees whose age is above 25 OR department is
‘Sales’.
SELECT * FROM employees
WHERE Age > 25 OR Department = 'Sales';
# Creating DataFrame
players = pd.DataFrame({
"Pno": [201, 202, 203, 204],
"Pname": ["David", "Steve", "Chris", "Mark"],
"Page": [29, 28, 30, 27],
"Income": [4500000, 6000000, 3200000, 3800000]
})
SELECT Name, Age, Role FROM staff WHERE City = 'Mumbai' ORDER BY Age ASC;
# Creating DataFrame
employees = pd.DataFrame({
"EmpID": [301, 302, 303, 304],
"EmpName": ["Aryan", "Neha", "Kabir", "Sonal"],
"EmpAge": [35, 29, 32, 26],
"Salary": [5500000, 4800000, 6200000, 3500000]
})
sql
CopyEdit
CREATE DATABASE Test2024;
USE Test2024;
CREATE TABLE workers (
Sno INT PRIMARY KEY,
Name VARCHAR(50),
Age INT,
Position VARCHAR(50),
Location VARCHAR(50)
);
sql
CopyEdit
INSERT INTO workers VALUES (1, 'Arjun', 34, 'Supervisor', 'Bengaluru'),
(2, 'Meera', 25, 'HR', 'Jaipur'),
(3, 'Nikhil', 29, 'Sales', 'Hyderabad');
sql
CopyEdit
SELECT MIN(Age) AS Youngest, MAX(Age) AS Oldest FROM workers;
sql
CopyEdit
SELECT Name, Age, Position FROM workers WHERE Location = 'Hyderabad' ORDER BY
Age ASC;
sql
CopyEdit
SELECT Location, MIN(Age) FROM workers GROUP BY Location;
sql
CopyEdit
SELECT * FROM workers WHERE Age > 28 OR Position = 'Sales';
(g) Count of Workers in Each Position
sql
CopyEdit
SELECT Position, COUNT(*) AS Total FROM workers GROUP BY Position;