Questions of SQL training
1) write a query to display the class wise average of m1 and m2 and m3
select a.classname, avg(c.m1), avg(c.m2), avg(c.m3), from cm a join sm b on a.classcode = b.classcode join
marks c on b.rollno =c.rollno
2) Write a query to display total cash and cheque collection
select sum(insta_amunt) as "total amount" from fees;
3) Write a query to display city wise total students.
select count(city) from sm group by city;
4) Write a query to display student list from the given city whose name starts with the letter with ‘a’.
select * from sm where (name like 'a%' and city='indore');
5) Write a query to display the list of classes and total collection of those classes for all those classes
whose collection more than 10 lakhs.
select a.classname, sum(c.insta_amunt) from sm b join cm a on a.classcode=b.classcode join fees c on
b.rollno=c.rollno group by a.classname having (sum(c.insta_amunt)>100000);
6) Write a query to display the list of student score more marks in m1 m2 and m3 in test 1 than the marks
scored by amol in test 1
Select a.rollno,a.name, b.classname, c.m1 from sm a join cm a.classcode = b.classcode join marks c on
a.rollno=c.rollno and c.testno=1and c.m1> (Select c.m1 from sm a join cm b on a.classcode=b.classcode join
a.rollno =c.rollno where a.name=’rahul’ and c.testno=1)
7) Write a query to display the average marks for those students whose avg mark is greater than the avg
marks of ‘fycse’ class
Select a.rollno, a.name, b.classname, avg((c.m1+c.m2+c.m3)/3) as avg from sm a join cm b on
a.classcode=b.classcode join marks c on a.rollno=c.rollno group by a.name, a.name, b.classname having
avg((c.m1+c.m2+c.m3)/3) >= (Select avg((c1.m1+c1.m2+c1.m3)/3) from sm a1 join cm b1 on
a1.classcode=b1.classcode join marks c1 on a1.rollno=c1.rollno and b1.classname=’fycse’)
8) Write a query to display the list of female student from the city where ravi and roma stays.
Select rollno, name, gender, city from sm where gender=’f’ and city= any (select city from sm where
name=’ravi’ or name=‘roma’);
9) Write a query to display the list of students who have scored more marks in m1 then the average of his
class marks in m1
Select a.roll, a.name, b.classame, c.m1 from sm a join cm b on a.classcode=b.classcode join marks c on
a.rollno=c.rollno where c.m1> (select avg(c1.m1) from join a1 join cm b1 on a=classcode=b1.classcode join
marks c1 on a1.rollno=c.rollno where a1.classcode= a.classcode)
10) Write a pl block to check the number is even or odd
11) Write a pl block to display first 10 prime numbers
12) Write a pl block to display the multiplication table for given range
13) Write a pl block to accept the number and obtain the sum of its digits
14) Write a pl block to reverse the given number
15) Write a pl block to find the occurrences of given character
16) Write a pl block to find the string is palindrome or not