Professional Documents
Culture Documents
SIMPLE SELECT :-
1. Select * from worker;
2. Select salary , region , grade from worker;
3. Select *, salary-2000 as salary from worker;
4. Select *, salary*12 as “annual salaries” from worker;
USING WHERE CLAUSE :-
5. Select * from worker where age < 28;
6. Select name from worker where region = ‘north’;
7. Select salary from worker where wshop=610;
USING NULL :-
8. Select * from worker where grade is null;
9. Select * from worker where grade is not null;
USING DISTINCT CLAUSE :-
10. Select distinct(name) from worker;
11. Select distinct(wshop) from worker;
USING (NOT,AND,OR) :-
12. Select * from worker where age>30 and wshop =610;
13. Select * from worker where wshop=230 and salary > 35000;
14. Select name, salary from worker where not(wshop=506);
15. Select name, salary from worker where not(region=‘west’ or
region=’centre’);
16. Select name from worker where wshop=610 or wshop=506;
17. Select * from worker where salary > 32000 and salary < 38000;
18. Select * from worker where grade > ‘A’ and grade < ‘C’;
19.Select * from worker where age> 30 and region =’west’;
USING IN :-
20. Select name from worker where wshop in(230,610);
21. Select name, salary from worker where region not in('west','centre');
USING BETWEEN :-
22. Select * from worker where salary between 32000 and 38000 ;
23. Select * from worker where age between 29 and 32 ;
USING LIKE :-
24. Select name, salary, age from worker where name like 'n%' ;
25. Select name, salary, age from worker where name like '%a' ;
26. Select name, salary, age from worker where name like '%k%' ;
27. Select * from worker where name not like '%a%';
28. Select * from worker where name like '_a%';
USING FUNCTIONS AND AGGREGATE FUNCTION :-
29.
30. Select max(salary) from worker;
31.
32. Select count(wno),sum(salary) from worker;
33. Select avg(salary),max(salary),min(salary) from worker;
34. Select max(salary)-min(salary) from worker;
USING GROUP BY AND HAVING CLAUSE :-
35.
36.
37.
38.
USING ORDER BY CLAUSE :-
39. Select * from worker order by salary;
40. Select * from worker order by name desc;
41. Select * from worker order by grade, salary desc;
USING UPDATE,DELETE,ALTER TABLE :-
42. Update worker set grade=’B’ where grade=’’;
43.
44. Delete from worker where grade=’C’ and salary < 30000;
45. Delete from worker where wshop=610 and age > 27;
46. Alter table workshop add(hiredate date);
Join of two tables
47.
48.
49.
50.
Python
Q 1. CSV= ADD()/ACCEPT() OR WON_COUNT()/SEARCH(). 5m
import csv
def accept():
f=open("result.csv",'a',newline='')
header=["st_id","st_name","game_name","result"]
std= int(input("enter student id"))
sname=input("enter student id")
game=input("enter game name")
result=input("enter result")
row=[std,sname,game,result]
csvwr=csv.writer(f)
csvwr.writerow(header)
csvwr.writerow(row)
f.close()
def won_count():
f=open("result.csv",'r')
csvrd=csv.reader(f,delimeter=',')
data=list(csv.rd)
c=0
for x in data:
if x[3]=="won":
c+=1
print(c)
f.close()
Q2. Line started with any word. 3m
def count_lines():
f=open("story.txt",'r')
w=f.readline()
c=0
for i in w:
if i[0]=='T':
c+=1
print('total line start with T',c)
f.close()
Q3. Cust_data() to ask user to enter their names and age to store data in
customer.dat file. 2m
import pickle as pk
def cust_data():
record={}
f=open("customer.dat",'bw')
while True:
record[n]=input("enter a name:")
record[a]=int(input("enter age:"))
pk.dump(record,f)
choice=input("wish to enter more record Y/N ?-")
if choice.upper()=='N':
break
print("records added to the file")
f.close()
Q4. Count() that will read the contents of text file named “report.txt” and
count the number of lines which starts with either “I” or “M”. 3m
def count():
f=open("report.txt",'r')
wr=f.readline()
c=0
for i in wr:
if i[0]=="I" or i[0]=="M":
c+=1
print("there are",c,"lines starting with 'I' or 'M'")
f.close()
Q5. Ending with any last word in line to count (txt). 2m
def count_lines():
f=open("story.txt",'r')
w=f.readline()
c=0
for i in w:
if i[-1]=='r':
c+=1
print('total lines ending with r:',c)
Q6. A binary file “student.dat” has structure
(admission_number,name,percentage) . Write a function countrec() in python
that would read contents of the file”student.dat” and display the details of
those students whose percentage is above 75.also display number of
students scoring above 75%.4m
import pickle as pk
def countrec():
f=open("student.dat",'rb')
n=0
try:
while True:
rec=pk.load(f)
if rec[2]>75:
print(rec[0],rec[1],rec[2],sep="\t")
n+=1
except:
f.close()
return n
Q7. Count ending with words.(txt). 2m
def displaywords():
f=open("story.txt",'r')
t=f.read()
w=t.split()
c=0
for i in w:
if i[-1]==’n’:
c+=1
print(c)
f.close()
Q8) What is the difference between switch and router?
ANS. Switch Router
1 it works on the same network type It works on network of a different type.
2 They are found in the same LAN They connect LANs and there can be
where there is a single path from multiple paths from source to destination
source to destination
Q9) What is the difference between a Hub and Switch?
ANS Hub Switch
1 It broadcast signals to all the devices it sends signals to only selected devices
connected instead of sending to all
2 It is not an intelligent device it is an intelligent device.
3 Hub is simply old type of device and switch is very sophisticated device and
is not generally used. widely used.
Uses The primary Key is used The Unique Key is used for
for indicating the rows preventing duplicate
uniquely. entries
Q38. What is Difference between DDL and DML?
Ans . The difference between DDL and DML:
DDL DML
It stands for Data Definition Language. It stands for Data Manipulation
Language.
It is used to create database schema It is used to add, retrieve or update
and can be used to define some the data.
constraints as well.
It basically defines the column It add or updates the row of the
(Attributes) of the table. table. These rows are called tuple.
Basic command present in DDL are BASIC command present in DML
CREATE, DROP, RENAME, ALTER etc. are UPDATE, INSERT, MERGE etc.
DDL is used to define the structure of a DML is used to manipulate the data
database. within the
database.