0% found this document useful (0 votes)
2 views6 pages

SQL

The document contains multiple sets of code snippets for different functionalities including calculating areas of geometric shapes, counting vowels in a file, managing employee records using pickle and CSV, and executing SQL queries for train and visitor data. Each set provides a specific functionality such as adding employees, displaying records, and performing database operations. The code also includes error handling and user input prompts for interaction.

Uploaded by

kiruthika
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)
2 views6 pages

SQL

The document contains multiple sets of code snippets for different functionalities including calculating areas of geometric shapes, counting vowels in a file, managing employee records using pickle and CSV, and executing SQL queries for train and visitor data. Each set provides a specific functionality such as adding employees, displaying records, and performing database operations. The code also includes error handling and user input prompts for interaction.

Uploaded by

kiruthika
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

Set 1:

import math
def area_circle():
r = float(input("Enter radius: "))
if r < 0:
print("Radius must be non-negative.")
return
print("Area of circle = {[Link]*r*r}")

def area_rectangle():
l = float(input("Enter length: "))
b = float(input("Enter breadth: "))
if l < 0 or b < 0:
print("Length and breadth must be non-negative.")
return
print("Area of rectangle =,”(l * b))

def area_triangle():
base = float(input("Enter base: "))
height = float(input("Enter height: "))
if base < 0 or height < 0:
print("Base and height must be non-negative.")
return
print("Area of triangle =”,(0.5 * base * height))

print("\n1. Area of Circle\n2. Area of Rectangle\n3. Area of Triangle\n4. Exit")


choice = input("Choose: ").strip()
if choice == '1':
area_circle()
elif choice == '2':
area_rectangle()
elif choice == '3':
area_triangle()
elif choice == '4':
print("Exiting.")
break
else:
print("Invalid choice.")
Set 2

def count_vowels_in_file(filename):
​ with open(filename, 'r') as f:
​ ​ text = [Link]()
​ ​ vowels = list('aeiouAEIOU')
​ ​ count = 0
​ ​ for ch in text:
​ ​ ​ if ch in vowels:
​​ ​ ​ count += 1
​ ​ print(f"Total vowels in '{filename}': {count}")

SET – 3

import pickle
filename = "[Link]"
def add_emp():
eno = input("Enter Eno: ")
name = input("Enter Name: ")
sal = float(input("Enter Salary: "))
try:
f = open(filename, "rb")
data = [Link](f)
[Link]()
except:
data = []

[Link]([eno, name, sal])

f = open(filename, "wb")
[Link](data, f)
[Link]()

print("Employee Added")

def display_less():
try:
f = open(filename, "rb")
data = [Link](f)
[Link]()
except:
data = []

print("Employees with salary < 40000:")


for e in data:
if e[2] < 40000:
print(e[0], e[1], e[2])

while True:
print("\[Link] Employee [Link] <40000 [Link]")
ch = input("Enter choice: ")

if ch == '1':
add_emp()
elif ch == '2':
display_less()
elif ch == '3':
break
else:
print("Wrong Choice")

Set 4​

stack = []

def push():
val = int(input("Enter value: "))
[Link](val)
print("Pushed")

def pop():
if len(stack) == 0:
print("Stack Empty")
else:
print("Popped:", [Link]())

def display():
if len(stack) == 0:
print("Stack Empty")
else:
print("Stack:", stack)

while True:
print("\[Link] [Link] [Link] [Link]")
ch = input("Enter choice: ")

if ch == '1':
push()
elif ch == '2':
pop()
elif ch == '3':
display()
elif ch == '4':
break
else:
print("Wrong Choice")

SET – 5

import csv

filename = "[Link]"

def add_emp():
eno = input("Enter Eno: ")
name = input("Enter Name: ")
sal = input("Enter Salary: ")

f = open(filename, "a", newline="")


w = [Link](f)
[Link]([eno, name, sal])
[Link]()
print("Employee Added")

def display_all():
f = open(filename, "r")
r = [Link](f)
for row in r:
print(row)
[Link]()

while True:
print("\[Link] Employee [Link] All [Link]")
ch = input("Enter choice: ")

if ch == '1':
add_emp()
elif ch == '2':
display_all()
elif ch == '3':
break
else:
print("Wrong Choice")

------------------------- SET 1 ---------------------------

-- 1. Display details of all trains which start from New Delhi


SELECT * FROM TRAIN WHERE START = 'New Delhi';

-- 2. Display PNR, Pname, Gender, Age of passengers below age 50


SELECT PNR, PNAME, GENDER, AGE FROM PASSENGERS WHERE AGE < 50;

-- 3. Display Tname and Pname for age between 50 and 60


SELECT [Link], [Link] FROM TRAIN, PASSENGERS WHERE
[Link] = [Link] AND AGE BETWEEN 50 AND 60;

-- 4. Display total number of male and female passengers


SELECT GENDER, COUNT(*) FROM PASSENGERS GROUP BY GENDER;

------------------------- SET 2 ---------------------------

-- 1. Display Name & Price of accessories in descending order of price


SELECT NAME, PRICE FROM ACCESSORIES ORDER BY PRICE DESC;

-- 2. Display ID and Sname for shops in Nehru Place


SELECT ID, SNAME FROM SHOPPE WHERE AREA = 'Nehru Place';

-- 3. Display name, minimum and maximum price of each accessory name


SELECT NAME, MIN(PRICE), MAX(PRICE) FROM ACCESSORIES GROUP BY NAME;

-- 4. Display all accessories containing word ‘Board’


SELECT * FROM ACCESSORIES WHERE NAME LIKE '%Board%';

------------------------- SET 3 ---------------------------

-- 1. Female visitors who paid more than 3000


SELECT VisitorName, Location FROM VISITORS WHERE Gender = 'F' AND Amount > 3000;

-- 2. Display unique locations


SELECT DISTINCT Location FROM VISITORS;

-- 3. Insert the given record


INSERT INTO VISITORS VALUES (8, 'Shilpa', 'F', 'Delhi', 2500);
-- 4. Display all visitors in ascending order of amount
SELECT * FROM VISITORS ORDER BY Amount ASC;

------------------------- SET 4 ---------------------------

-- 1. Display all trains that start from Howrah


SELECT * FROM TRAIN WHERE START = 'Howrah';

-- 2. Display PNR, Pname for passengers whose TNO = 13005


SELECT PNR, PNAME FROM PASSENGERS WHERE TNO = '13005';

-- 3. Display Tname and Start where End = 'Ajmer'


SELECT TNAME, START FROM TRAIN WHERE END = 'Ajmer';

-- 4. Display count of passengers travelling in each train


SELECT TNO, COUNT(*) FROM PASSENGERS GROUP BY TNO;

------------------------- SET 5 ---------------------------

-- 1. Employees in descending order of date of joining (DOJ)


SELECT * FROM EMPLOYEE ORDER BY DOJ DESC;

-- 2. Display Name & Designation for Sgrade S02 or S03


SELECT NAME, DESIG FROM EMPLOYEE WHERE SGADE IN ('S02','S03');

-- 3. Display Name, Designation, Sgrade for employees who joined in 2009


SELECT NAME, DESIG, SGADE FROM EMPLOYEE WHERE YEAR(DOJ) = 2009;

-- 4. Display Name, Designation, Salary, HRA where salary < 50000


SELECT [Link], [Link], [Link], [Link]
FROM EMPLOYEE, SALGRADE
WHERE [Link] = [Link]
AND [Link] < 50000;

You might also like