SQL Problems For Practice
SQL Problems For Practice
Solution:
1. select count(*) from Student where dept=’IT’;
2. select mark from Student where mark>100;
Write SQL query for the below student database
Consider the student database.
Student (regno,name,dept,mark,city,percentage,mobileno)
Give the expression in SQL to express each of the following queries:
1.Rename student name attribute as sname
2.Write a query to display student name second character as ‘c’
3. Write a query to display the mark range from 70 to 85 of CSE department
4. Write a query to add new column as rollno in student table
Solution:
1. ALTER Table Student
Rename column name to sname;
2. select name from Student where name LIKE ‘_c%’;
3. select mark from Student where dept = ‘CSE’ AND mark BETWEEN(70 AND 85);
4. ALTER Table Student
ADD rollno int;
Write SQL query for the below employee database
Consider the employee database.
Emp(ename,street,city,dept)
Works(ename,companyname,salary)
Company(companyname,city)
Manages(ename,managername)
Give the expression in SQL to express each of the following queries:
1. Write a query to fetch the number of employees working in the department
‘HR’.
2.Write a query to get the salary >60000.
3. Write a query to find all the employees whose salary is between 60000 to
100000.
4.Write a query to find the names of employees that begin with ‘A’
Solution:
1. Select count(*) from Emp where dept =’HR’;
2. Select ename from Works where salary>60000;
3. Select ename from Works where salary BETWEEN 60000 AND 100000;
4. Select ename from Emp where ename LIKE ‘A%’;
Solution:
(i)SELECT name
FROM member
WHERE member.memb_no=borrowed.memb_no
AND books.isbn=borrowed.isbn
AND books.publisher=’McGraw Hill’;
Solution: