You are on page 1of 19

Toc H PUBLIC SCHOOL, Vyttila

CLASS 12 COMPUTER SCIENCE


TENTATIVE RECORD QUESTIONS
FOR 2022 – 23

1. Write a Python program which accepts a number from the user and pass it as
argument to the function. The function should return the sum of the digits of this
number. Display the number
as well as the sum.

def fun1(no):
s=0
while no>0: OUTPUT
dig=no%10
s+=dig Enter
number: 12345
The sum of
digits of 12345 is 15
no//=10
return s

no=int(input("Enter number: "))


print('The sum of digits of',no,'is',fun1(no))

2. Write a Python program to store ‘n’ numbers into a list and pass it to a
function. The function should count the number of even numbers in the list
divisible by 9 and print the count
as the output. (limit ‘n’ should be entered by the user)

def fun1(l):
c=0
for i in l:
if i%18==0:
c+=1
print('Number of even nos divisible by 9 are',c)
OUTPUT

n=int(input("Enter no of entries: ")) Enter


no of entries: 3
l=[] Enter
a number: 12
for i in range(n): Enter
a number: 18
no=int(input("Enter a number: ")) Enter
a number: 54
l.append(no) Number
of even nos divisible by 9 are 2

fun1(l)
3. Write a Python program to accept a string from the user and pass it to a
function. The function should return the value 1 if the string starts and ends with
a vowel else return 0.
If the value returned is 1 print ‘String entered correctly’ else ‘Invalid
string’.

def fun1(s):
if s[0] in 'AEIOUaeiou' and s[-1] in 'AEIOUaeiou':
return 1
else: OUTPUT
return 0 Enter string:
Chevy
s=input("Enter string: ") Invalid string
fun1(s)
a=fun1(s)
if a==1:
print('String entered correctly')
else:
print('Invalid string')

4. Write a Python program to accept ‘n’ numbers into a tuple. Pass this tuple as
parameter to a function. Print the number of elements in the tuple which are
“Perfect”
(6 is a perfect number as 6 = sum of its factors 1+2+3).

def fun1(t):
c=0
for i in t:
s=0
a=i OUTPUT
for x in range(1,(i//2)+1): Enter no of
entries: 3
if a%x==0: Enter number: 6
s+=x Enter number: 12
if i==s: Enter number: 28
c+=1 2 perfect numbers
print(c,'perfect numbers')

n=int(input("Enter no of entries: "))


t=()
for i in range (n):
no=int(input("Enter number: "))
t+=(no,)

fun1(t)

5. Write a Python program to accept ‘n’ elements in a dictionary of the following


format bookno -> is the key and the tuple (bk_name, type, price) is the
corresponding ‘value’.
Pass this dictionary to a function. The function should ask the user for a
‘bookno’. Search for this ‘bookno’ in the dictionary and print the corresponding
bk_name, type, price as
output.

def fun1(d):
search=int(input("Enter book number to be searched: "))
OUTPUT
k=d.keys() Enter
no of key value pairs: 2
if search in k: Enter
book number: 10
print(d[search]) Enter
book name: heyjude
Enter
type: fiction
n=int(input("Enter no of key value pairs: ")) Enter
price: 500
d={} Enter
book number: 92
for i in range (n): Enter
book name: thebeatles
bookno=int(input("Enter book number: ")) Enter
type: non-fiction
bk_name=input("Enter book name: ") Enter
price: 1000
type=input("Enter type: ") Enter
book number to be searched: 92
price=int(input("Enter price: "))
('thebeatles', 'non-fiction', 1000)
d[bookno]=(bk_name,type,price)

fun1(d)

6.Write a menu driven program in Python which accepts a number and does the
following:
a. Pass the number to func1(). This function should print whether the number
is ‘a Palindrome’ or not
b. Pass this number to func2(), which in turn will check whether the number
is a prime number or not.

def func1(no):
s=0
num=no
while num>0:
dig=num%10
s=s*10+dig OUTPUT
num//=10 1) Check if number is a
palindrome
if no==s: 2) Check if the number
is prime
print("Palindrome") Enter choice: 1
else: Enter number: 121
print("Not a palindrome") Palindrome
Do you want to continue?
[yes/no]yes
def func2(no): 1) Check if number is a
palindrome
a=no 2) Check if the number
is prime
for x in range (2,(no//2)+1): Enter choice: 2
if a%x==0: Enter number: 14
print("Not prime") Not prime
break Do you want to continue?
[yes/no]no
else:
print("Prime number")

ans='yes'
while ans.lower()=='yes':
print("1) Check if number is a palindrome")
print("2) Check if the number is prime")
c=int(input("Enter choice: "))
no=int(input("Enter number: "))
if c==1:
func1(no)
elif c==2:
func2(no)
else:
print("Wrong choice")
ans=input("Do you want to continue?[yes/no]")

7. Write a Python program to accept a number and print whether it is a Disarium


number. A number is said to be the Disarium number when the sum of its digit raised
to the power of their
respective positions becomes equal to the number itself.
no=int(input("Enter a number: "))
a=0
s=str(no)
OUTPUT
for i in s: Enter
a number: 175
b=eval(i)
Disarium number
a+=b**(s.index(i)+1)
if a==no:
print("Disarium number")
else:
print("Not a Disarium number")

8. Write a program to find the duplicate elements in a list given by the user.

l=[]
l1=[]
l2=[]
n=int(input("Enter number of entries: "))
OUTPUT
for i in range (n): Enter
number of entries: 4
no=int(input("Enter number: ")) Enter
number: 13
l.append(no) Enter
number: 14
Enter
number: 14
for i in l: Enter
number: 15
if i not in l1:
Duplicate elements are [14]
l1.append(i)
else:
l2.append(i)
print("Duplicate elements are ",l2)

9. Write a Python program to accept a filename from the user and print the smallest
line in the text file.

fname=input("Enter file name: ")


f1=open(fname) OUTPUT
l=f1.readline() Enter file name:
trial1.txt
l1=f1.readlines() Smallest line is:
heyjude
for i in l1:
if len(i)<len(l):
l=i

print("Smallest line is: ",l)

10. Write a Python program to accept ‘n’ strings and store it to “original.txt”.
Copy all the lines containing the letter given by the user to another file
“copy.txt”.

f=open('original.txt','w')
n=int(input("Enter no of entries: "))
for i in range (n):
s=input("Enter string: ")
OUTPUT
f.write(s+'\n')
Enter no of entries: 3
f.close()
Enter string: time

Enter string: to
letter=input("Enter letter: ")
Enter string: sleep
Enter letter: t
f=open('original.txt')
time
data=f.readlines()
to
f1=open('copy.txt','w')

for i in data:
if letter in i:
f1.write(i)
f1.close()

f2=open('copy.txt')
a=f2.read()
print(a)
f2.close()

11. Write a Python program to accept ‘n’ names and store it to a file where
filename is given by the user. Accept a name from the user. Print whether this name
appears in the file.
Print appropriate message on the screen.

fname=input("Enter file name: ")


f=open(fname,'w')
n=int(input("Enter no of names: "))
for i in range (n): OUTPUT
s=input("Enter name: ") Enter file
name: trial1.txt
f.write(s+' ') Enter no of
names: 3
f.close() Enter name:
jane
Enter name:
rachel
name=input("Enter a name: ") Enter name:
juby
Enter a
name: rachel
f=open(fname) rachel
appears in file
data=f.read()
f.close()
if name in data:
print(name, 'appears in file')
else:
print(name,"does not appear in file")

12. Write a Python program to define a dictionary with keys starting from 1 to 7.
The corresponding value will be the name of the day. Eg. 1: “Sunday” as the first
element of the
dictionary. Write this dictionary to the binary file “day.dat”. Generate a
number between 1 and 7 randomly and search for this number in the file and print
the corresponding name of
the day with its number.

import pickle
import random

d={1:'Sunday',2:'Monday',3:'Tuesday',4:'Wednesday',5:'Thursday',6:'Friday',7:'Satur
day'}
f=open('day.dat','wb')
OUTPUT
pickle.dump(d,f)
Saturday 7
f.close()

no=random.randint(1,7)

f=open('day.dat','rb')
data=pickle.load(f)
f.close()

for i in data:
if no==i:
print(data[i],i)

13. Write a Python program to accept ‘n’ elements for a dictionary. The key of the
dictionary has to be ‘fam_code’ while the value will be a list made up
of ‘name’, ‘family_name’. Write this dictionary to a binary file ‘family.dat’.
Display the content of ‘family.dat’ where family_name is a palindrome.

import pickle

d={}
n=int(input("Enter no of key-value pairs: ")) OUTPUT
for i in range(n): Enter no of
key-value pairs: 2
fam_code=int(input("Enter family code: ")) Enter family
code: 1
name=input("Enter name: ") Enter name:
ringo
family_name=input("Enter family name: ") Enter family
name: starr
d[fam_code]=[name,family_name] Enter family
code: 7
Enter name:
george
f=open("family.dat",'wb') Enter family
name: kkk
pickle.dump(d,f) 7 ['george',
'kkk']
f.close()

f1=open("family.dat",'rb')
data=pickle.load(f1)

for i in data:
if data[i][1]==data[i][1][::-1]:
print(i,data[i])
f1.close()

14. Write a Python program to accept a list of information given as


[[slno,country,currency],[……],[….]…] where slno should be 1 for the 0th element of
the list, country and currency
should be taken from the user. Write this list to a CSV file and display the
contents of this file as output.

import csv

l=[]
heading=['slno','country','currency']
n=int(input("Enter number of lists: "))
OUTPUT
for i in range (n):
Enter number of lists: 3
country=input("Enter country: ")
Enter country: india
currency=input("Enter currency: ")
Enter currency: ruppee
l.append([i+1,country,currency])
Enter country: america

Enter currency: dollar

Enter country: britan


with open ('country.csv','w',newline='') as f:
Enter currency: pound
data=csv.writer(f,delimiter=',')
['slno', 'country', 'currency']
data.writerow(heading)
['1', 'india', 'ruppee']
for i in l:
['2', 'qatar', 'riyal']
data.writerow(i)
['3', 'britan', 'pound']

f1=open('country.csv','r')
a=csv.reader(f1)
for i in a:
print(i)
f1.close()

15. Write a Python program to implement a stack with country_code, country_name as


information stored in stack in the form of nested list (push, pop, display
options).

stack=[]
n=int(input("Enter number of entries: "))
OUTPUT
for i in range (n): Enter
number of entries: 1
country_code=int(input("Enter country code: ")) Enter
country code: 10
country_name=input("Enter country name: ") Enter
country name: india
stack.append([country_code, country_name]) 1) To
insert a list
2) To
delete a list
ans='yes' 3) To
display list
while ans.lower()=='yes': Enter
choice: 1
print("1) To insert a list") Enter
country code: 20
print("2) To delete a list") Enter
country name: usa
print("3) To display list") Do you
want to continue?[yes/no]yes
c=int(input("Enter choice: ")) 1) To
insert a list
2) To
delete a list
if c==1: 3) To
display list
a=int(input("Enter country code: ")) Enter
choice: 3
b=input("Enter country name: ") [[10,
'india'], [20, 'usa']]
stack.append([a,b]) Do you
want to continue?[yes/no]yes
1) To
insert a list
2) To
delete a list
elif c==2: 3) To
display list
if stack==[]: Enter
choice: 2
print("Empty stack") Do you
want to continue?[yes/no]yes
else: 1) To
insert a list
stack.pop() 2) To
delete a list
3) To
display list
Enter
choice: 3
elif c==3: [[10,
'india']]
print(stack) Do you
want to continue?[yes/no]no

else:
print("Wrong choice")
ans=input("Do you want to continue?[yes/no]")
16. Write a Python program to implement a stack with district_code, district of
Kerala as information stored in stack in the form of dictionary with
‘district_code’ as key and ‘district’ as value.

stack=[]
OUTPUT
for i in range (3):
Enter district code: WA
district_code=input("Enter district code: ")
Enter district: Wayanad
district=input("Enter district: ")
Enter district code: PL
stack.append({district_code:district})
Enter district: Palakkad
print(stack)
Enter district code: ER

Enter district: Ernakulam

[{'WA': 'Wayanad'}, {'PL': 'Palakkad'}, {'ER': 'Ernakulam'}]

17. Write a Python program to create a database ‘world_info’. Use this database
and create a table with the following details :

Table name : country


Columns are :
country_no Primary Key of type numeric,
country_name char(10) not null unique,
language char(15)
Display ‘Table created’ as output.

import mysql.connector as c
db=c.connect(host='localhost',user='root',passwd='heyjude')
OUTPUT
cursor=db.cursor()
Table created
cursor.execute('create database world_info')

cursor.execute('use world_info')
cursor.execute("create table country (country_no numeric Primary key,country_name
char(10) NOT NULL unique,language char(15))")
print("Table created")

18. Write a Python program to write 3 records to the above table ‘country’.
Display the contents of ‘country’ table as output.

import mysql.connector as c
db=c.connect(host='localhost',user='root',passwd='heyjude')
cursor=db.cursor()
OUTPUT
cursor.execute('use world_info')
(1, 'India', 'Hindi')
cursor.execute("Insert into country values(1,'India','Hindi')")
(2, 'Qatar', 'Arabic')
cursor.execute("Insert into country values(2,'Qatar','Arabic')")
(3, 'USA', 'English')
cursor.execute("Insert into country values(3,'USA','English')")
db.commit()
cursor.execute('select * from country')
result=cursor.fetchall()
for x in result:
print(x)

19. Write a Python program to update the ‘country’ table with a new language for a
given country_no received from the user. Print the new contents of
the ‘country’ table as output.

import mysql.connector as c
db=c.connect(host='localhost',user='root',passwd='heyjude',database='world_info')
cursor=db.cursor()
OUTPUT
no=int(input("Enter country number: "))
Enter country number: 1
lan=input("Enter language: ")
Enter language: Malayalam
data=(lan,no)
(1, 'India', 'Malayalam')
u="update country set language=%s where country_no=%s"
(2, 'Qatar', 'Arabic')
cursor.execute(u,data)
(3, 'USA', 'English')
db.commit()
cursor.execute('select * from country')
result=cursor.fetchall()
for x in result:
print(x)

20.Write a Python program to delete country details from the ‘country’ table for a
given country number given by the user. Display the table contents
after deletion as the output.

import mysql.connector as c
db=c.connect(host='localhost',user='root',passwd='heyjude',database='world_info')
OUTPUT
country_no=int(input("Enter country number: "))
Enter country number: 2
cursor=db.cursor()
(1, 'India', 'Malayalam')
cursor.execute("Delete from country where country_no=%s"%(country_no,))
(3, 'USA', 'English')
db.commit()

cursor.execute('select * from country')


result=cursor.fetchall()
for x in result:
print(x)

21. Fill up with appropriate statements in the given stub program:

ANSWERS
import ____________ as mc
mysql.connector
mydb=mc.connect(host="localhost",user="root",passwd="root",database="school")

mycursor = _______________
mydb.cursor
mycursor.execute("_________") # to display the list of tables
SHOW TABLES
for x in _________:
mycursor
print(x)

MYSQL COMMANDS

1) Consider the following table:


Table: Directory
No Name Phone Address
1 Arpit Kumar 7045634 Subhash Nagar
2 Ram Sharma 5563412 Vikas Nagar
3 Vikas Malhotra 7865467 Palam Nagar
4 Rohit Arora 2235434 Preet Vihar
5 Kisan Kaushik 5567845 Pashim Vihar
6 Rahul Verma 7057456 Subhash Nagar
7 Rakesh Gulati 7026519 Palam Nagar

Write the SQL commands for the following:

(a) To select all the information of employees of ‘Subhash Nagar’ area.

select * from Directory where address='Subhash Nagar';

+----+-------------+---------+---------------+
| No | Name | Phone | Address |
+----+-------------+---------+---------------+
| 1 | Arpit Kumar | 7045634 | Subhash Nagar |
| 6 | Rahul Verma | 7057456 | Subhash Nagar |
+----+-------------+---------+---------------+

(b) Update the database set the phone no as 7047645 where phone number is
7057456.
update Directory set phone=7047645 where phone=7057456;

+----+----------------+---------+---------------+
| No | Name | Phone | Address |
+----+----------------+---------+---------------+
| 1 | Arpit Kumar | 7045634 | Subhash Nagar |
| 2 | Ram Sharma | 5563412 | Vikas Nagar |
| 3 | Vikas Malhotra | 7865467 | Palam Nagar |
| 4 | Rohit Arora | 2235434 | Preet Vihar |
| 5 | Kisan Kaushik | 5567845 | Pashim Vihar |
| 6 | Rahul Verma | 7047645 | Subhash Nagar |
| 7 | Rakesh Gulati | 7026519 | Palam Nagar |
+----+----------------+---------+---------------+

(c) To display the data for Arpit, Rahul and Kisan.

select * from Directory where name in ('Arpit Kumar','Rahul Verma','Kisan


Kaushik');

+----+---------------+---------+---------------+
| No | Name | Phone | Address |
+----+---------------+---------+---------------+
| 1 | Arpit Kumar | 7045634 | Subhash Nagar |
| 5 | Kisan Kaushik | 5567845 | Pashim Vihar |
| 6 | Rahul Verma | 7057456 | Subhash Nagar |
+----+---------------+---------+---------------+

(d) To delete the rows where the address is ‘Preet Vihar’.

delete from Directory where Address='Preet Vihar';

+----+----------------+---------+---------------+
| No | Name | Phone | Address |
+----+----------------+---------+---------------+
| 1 | Arpit Kumar | 7045634 | Subhash Nagar |
| 2 | Ram Sharma | 5563412 | Vikas Nagar |
| 3 | Vikas Malhotra | 7865467 | Palam Nagar |
| 5 | Kisan Kaushik | 5567845 | Pashim Vihar |
| 6 | Rahul Verma | 7047645 | Subhash Nagar |
| 7 | Rakesh Gulati | 7026519 | Palam Nagar |
+----+----------------+---------+---------------+

(e) To delete the table Physically.

drop table Directory;

(f) Give the output:

(i) Select count(Distinct Address) from Directory;

+-------------------------+
| count(Distinct Address) |
+-------------------------+
| 6 |
+-------------------------+

(ii) Select Name from Directory where phone=7026519;

+---------------+
| Name |
+---------------+
| Rakesh Gulati |
+---------------+

(iii) Select Phone from Directory where address like ‘P%’;

+---------+
| Phone |
+---------+
| 2235434 |
| 5567845 |
| 7026519 |
+---------+

(iv) Select Name, Phone from Directory where Name like “R_%”;

+---------------+---------+
| Name | Phone |
+---------------+---------+
| Ram Sharma | 5563412 |
| Rohit Arora | 2235434 |
| Rahul Verma | 7057456 |
| Rakesh Gulati | 7026519 |
+---------------+---------+

2)Consider the following tables Sender and Recipient. Write SQL commands for the
statements (i) to (iv) and give outputs for SQL queries under (v)

Table: Sender

SenderlD SenderName SenderAddress SenderCity


ND01 R Jain 2 ABC Appts New Delhi
MU02 H Sinha 12 Newtown Mumbai
MU15 S Jha 27/A Park Street Mumbai
ND50 T Prasad 122-K SDA New Delhi

Table: Recipient

RecID SenderlD RecName RecAddress RecCity


KO05 ND01 R Bajpayee 5 Central Avenue Kolkata
ND08 MU02 S Mahajan 116 A Vihar New Delhi
MU19 ND01 H Singh 2A Andheri East Mumbai
MU32 MU15 P K Swamy B5 C S Terminus Mumbai
ND48 ND50 S Tripathi 13 B1 D Mayur Vihar New Delhi
(i) To display the names of all Senders from Mumbai.

select * from sender where SenderCity='Mumbai';


+----------+------------+-------------------+------------+
| SenderID | SenderName | SenderAddress | SenderCity |
+----------+------------+-------------------+------------+
| MU02 | H Sinha | 12 Newtown | Mumbai |
| MU15 | S Jha | 27/A Park Street | Mumbai |
+----------+------------+-------------------+------------+

(ii) To display the RecID, SenderName, SenderAddress, RecName, RecAddress for


every Recipient.

select RecID,SenderName,SenderAddress,RecName,RecAddress from


Recipient,Sender where Recipient.SenderID = Sender.SenderID;

+-------+------------+-------------------+------------
+-----------------------+
| RecID | SenderName | SenderAddress | RecName | RecAddress
|
+-------+------------+-------------------+------------
+-----------------------+
| KO05 | R Jain | 2 ABC Appts | R Bajpayee | 5 Central Avenue
|
| MU19 | R Jain | 2 ABC Appts | H Singh | 2A Andheri
|
| ND08 | H Sinha | 12 Newtown | S Mahajan | 116 A Vihar
|
| MU32 | S Jha | 27/A Park Street | P K Swamy | B5 C S Terminus
|
| ND48 | T Prasad | 122-K SDA | S Tripathi | 13 B1 D Mayur Vihar
|
+-------+------------+-------------------+------------
+-----------------------+

(iii) To display Recipient details in ascending order of RecName.

select * from Recipient order by RecName;

+-------+----------+------------+-----------------------+-------------+
| RecID | SenderID | RecName | RecAddress | RecCity |
+-------+----------+------------+-----------------------+-------------+
| MU19 | ND01 | H Singh | 2A Andheri | East Mumbai |
| MU32 | MU15 | P K Swamy | B5 C S Terminus | Mumbai |
| KO05 | ND01 | R Bajpayee | 5 Central Avenue | Kolkata |
| ND08 | MU02 | S Mahajan | 116 A Vihar | New Delhi |
| ND48 | ND50 | S Tripathi | 13 B1 D Mayur Vihar | New Delhi |
+-------+----------+------------+-----------------------+-------------+

(iv) To display number of Recipients from each city.

select RecCity, count(*) from Recipient group by RecCity;


+-------------+----------+
| RecCity | count(*) |
+-------------+----------+
| East Mumbai | 1 |
| Kolkata | 1 |
| Mumbai | 1 |
| New Delhi | 2 |
+-------------+----------+

(v) Give the output:

(a) SELECT DISTINCT SenderCity FROM Sender;

+------------+
| SenderCity |
+------------+
| New Delhi |
| Mumbai |
+------------+

(b) SELECT A. SenderName, B.RecName FROM Sender A, Recipient B WHERE A. SenderID


= B.SenderID AND B.RecCity = ‘Mumbai’;

+------------+-----------+
| SenderName | RecName |
+------------+-----------+
| S Jha | P K Swamy |
+------------+-----------+

(c) SELECT RecName, RecAddress FROM Recipient WHERE RecCity NOT IN (‘Mumbai’,
‘Kolkata’);

+------------+-----------------------+
| RecName | RecAddress |
+------------+-----------------------+
| S Mahajan | 116 A Vihar |
| H Singh | 2A Andheri |
| S Tripathi | 13 B1 D Mayur Vihar |
+------------+-----------------------+

(d) SELECT RecID, RecName FROM Recipient WHERE SenderID=’MU02’ OR SenderID=’ND50’;

+-------+------------+
| RecID | RecName |
+-------+------------+
| ND08 | S Mahajan |
| ND48 | S Tripathi |
+-------+------------+

3) Consider the following tables ACTIVITY and COACH and answer (a) and (b) parts
of this question:

Table: Activity
Acode ActivityName Stadium ParticipantsNum Prize Money Schedule
Date
1001 Relay 100x4 Star Annex 16 10000 23-Jan-
2004
1002 High jump Star Annex 10 12000 12-Dec-
2003
1003 Shot Put Super Power 12 8000 14-Feb-
2004
1005 Long Jump Star Annex 12 9000 01-Jan-
2004
1008 Discuss Throw Super Power 10 15000 19-Mar-
2004

Table: Coach
Pcode Name Acode
1 Ahmad Hussain 1001
2 Ravinder 1008
3 Janila 1001
4 Naaz 1003

(a) Write SQL commands for the following statements:

(i) To display the names of all activities with their Acodes in descending order.

select ActivityName from Activity order by Acode DESC;

+---------------+
| ActivityName |
+---------------+
| Discuss Throw |
| Long Jump |
| Shot Put |
| High jump |
| Relay 100x4 |
+---------------+

(ii) To display sum of PrizeMoney for the Activities played in each of the Stadium
separately.

select sum(PrizeMoney) from Activity group by Stadium;

+-----------------+
| sum(PrizeMoney) |
+-----------------+
| 31000 |
| 23000 |
+-----------------+

(iii) To display the coach’s name and ACodes in ascending order of ACode from the
table COACH.

select Name,Acode from Coach order by Acode;


+---------------+-------+
| Name | Acode |
+---------------+-------+
| Ahmad Hussain | 1001 |
| Janila | 1001 |
| Naaz | 1003 |
| Ravinder | 1008 |
+---------------+-------+

(iv) To display the content of the Activity table whose ScheduleDate earlier than
01/01/2005 in ascending order of ParticipantsNum.

select * from Activity where ScheduleDate<'2005/01/01' order by


ParticipantsNum;

+-------+---------------+-------------+-----------------+------------
+--------------+
| Acode | ActivityName | Stadium | ParticipantsNum | PrizeMoney |
ScheduleDate |
+-------+---------------+-------------+-----------------+------------
+--------------+
| 1002 | High jump | Star Annex | 10 | 12000 | 2003-
12-12 |
| 1008 | Discuss Throw | Super Power | 10 | 15000 | 2004-
03-19 |
| 1003 | Shot Put | Super Power | 12 | 8000 | 2004-
02-14 |
| 1005 | Long Jump | Star Annex | 12 | 9000 | 2004-
01-01 |
| 1001 | Relay 100x4 | Star Annex | 16 | 10000 | 2004-
01-23 |
+-------+---------------+-------------+-----------------+------------
+--------------+

(b) Give the output of the following SQL queries:

(i) SELECT COUNT(DISTINCT ParticipantsNum) FROM ACTIVITY;

+---------------------------------+
| COUNT(DISTINCT ParticipantsNum) |
+---------------------------------+
| 3 |
+---------------------------------+

(ii) SELECT MAX(ScheduleDate), MIN(ScheduleDate) FROM ACTIVITY;

+-------------------+-------------------+
| MAX(ScheduleDate) | MIN(ScheduleDate) |
+-------------------+-------------------+
| 2004-03-19 | 2003-12-12 |
+-------------------+-------------------+

(iii) SELECT Name, ActivityName FROM ACTIVITY A, COACH C WHERE A.Acode=C.Acode AND
A.ParticipantsNum=10;

+----------+---------------+
| Name | ActivityName |
+----------+---------------+
| Ravinder | Discuss Throw |
+----------+---------------+

(iv) SELECT DISTINCT Acode FROM COACH;


+-------+
| Acode |
+-------+
| 1001 |
| 1008 |
| 1003 |
+-------+

You might also like