Class 12 Observation - SQL-2
Class 12 Observation - SQL-2
1) Write command To change the colour of garment with code as 116 to “Orange”.
2) Write command to increase the price of all XL garments by 10%
3) Write command to delete the record with GCode “116”
2. Consider the table TEACHER given below. Write commands in SQL for (1) to (3) and output for (4)
i.
To
(i) Display the SurNames, FirstNames and Cities of people residing in Udhamwara city.
(ii) Display the Person Ids (PID), cities and Pincodes of persons in descending order of Pincodes.
(iii) Display the First Names and cities of all the females getting Basic salaries above 40000.
(iv) Display First Names and Basic Salaries of all the persons whose firstnames starts with “G”.
(v) SELECT Surname FROM Persons Where BasicSalary>=50000;
Consider a table Emp having following records a(Null values are excluded while (avg)aggregate
function)
EMP
mysql> Select Job, Sum(sal) from EMP Group By Job HAVING Avg(sal)>=7000;
mysql> Select Job, Sum(sal) from EMP Group By Job HAVING Count(*)>=5;
mysql> Select Job, Min(sal),Max(sal), Avg(sal) from EMP Group By Job HAVING Sum(sal)>=8000;
o/p – 20 lines
mysql> SELECT Name, Fname, City FROM Student Where Name LIKE ‘R%’ ORDER BY Class;
o/p – 20 lines
SQL - JOINS
With reference to these tables, Write commands in SQL for (i) and (ii) and output for (iii) below:
(i) Display the CustNo, CustAddress and corresponding SetName for each customer.
(ii) Display the Customer Details for each customer who uses a Nokia handset.
(iii) select SetNo, SetName from Handsets, customer where SetNo = SetCode and CustAddress =
'Delhi';
O/P – 10 lines
2. Consider the tables DOCTORS and PATIENTS given below:
W1th reference to these tables, wnte commands m SQL for (1) and (II) and output for (iii) below:
(i)
Display the PatNo, PatName and corresponding DocName for each patient
(ii) Display the list of all patients whoseOPD_Days are MWF.
(iii) select OPD_Days, Count(*) from Doctors, Patients where Patients.Department =
Doctors.Department Group by OPD_Days;
O/P – 10 lines
With reference to these tables, write commands in SQL for (i) and (ii) and output for (iii) below:
i. To display flight number, source, airlines of those flights where fare is less than Rs. 10000.
ii. To count total no of Indian Airlines flights starting from various cities.
iii. SELECT FLIGHTS.FNO, NO_OF_FL, AIRLINES FROM FLIGHTS,FARES WHERE FLIGHTS.FNO =
FARES.FNO AND
SOURCE=’DELHI’;
O/P – 10 lines
SQL - INTERFACE
1. To create table
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",passwd="root" ,database="school")
mycursor=mydb.cursor()
mycursor.execute("create table student(rollno int(3) primary key,name varchar(20),age int(2))")
B)
C)
7. Consider a table EMP , Find the output for the given code segments
a) # Assume All basic setup related to connection and cursor creation is already done
query="select * from emp"
mycursor.execute(query)
result = mycursor.fetchone()
result = mycursor.fetchone()
print(result[0],result[1],result[2])
print(“Total records selected “, mycursor.rowcount)
b) # Assume All basic setup related to connection and cursor creation is already done
query="select * from emp where salary >50000;"
mycursor.execute(query)
result = mycursor.fetchall()
for i in result:
print(i[0],‟#‟,i[2])
print(“Total records selected “, mycursor.rowcount)
c) # Assume All basic setup related to connection and cursor creation is already done
query="select * from emp where salary >30000;"
mycursor.execute(query)
results = mycursor.fetchone()
print(“Total records selected “, mycursor.rowcount)
results = mycursor.fetchone()
print(“Total records selected “, mycursor.rowcount)
results = mycursor.fetchmany(2)
print(“Total records selected “, mycursor.rowcount)
d) # Assume All basic setup related to connection and cursor creation is already done
query="select * from emp"
mycursor.execute(query)
results = mycursor.fetchone()
results = mycursor.fetchall()
for i in results:
print('Name:' , i[1],'Salary:',i[3])