Question
Question
28. Write SQL query to find total number of students having class id 5 and age greater than 19.
-Select count(*) from student where class_id=5 and age>19.
29. Write SQL query to find average age of students whose class id is 4 and section is B.
-Select avg(age) from student where class_id=4 and section=’B’;
30. Write SQL query to select students whose address starts with letter ‘B’.
-Select * from student where address like ‘B%’;
31. Write SQL query to count those students whose name ends with letter ‘R’.
- Select count(name) from student where name like ‘%R’;
32. Write SQL query to select name and age of students whose having address btm or ktm.
-Select name, age from Student where address=’btm’ or address=‘Ktm’;
33. Write SQL query to select sum of age of students having id 1,2 and 3.
-Select sum(age) from Student where id=1 or id=2 or id=3;
34. Write SQL query to select students whose age is between 18 and 22.
-Select * from Student Where Age between 18 and 22.
35. Write SQL query to select total students of each age group.
-
36. Write SQL query to select class id, name and maximum age of students studying in each class.
-
37. Write SQL query to select student’s records by arranging in descending order on the basis of student id.
-Select * from Student order by Student_id Desc;
38. Write SQL query to select student id and name by of students whose age is greater than 20 after arranging
records in alphabetical order on the basis of name.
-Select student_id, name from Student where age>20 order by name ASC;
39. Write SQL query to select records of student whose age is maximum among all the students.
-Select * from student where age=(select max(age)from student);
40. Write SQL query to select student id and name of student whose student id is maximum among all the
students.
-Select student_id, name from student where student_id=(Select max(student_id) from Student);
41. Write SQL query to select name and age of student whose age is minimum than the average age of all
students.
-Select name, age from student where age<(select avg(age) from student;
42. Write SQL query to list all the students except ‘btm & ‘ktm in asc order of age.
-Select * from Student Where address<>‘btm’ or address<>’Ktm’ order by age asc;
43. Write SQL query the students who does not belong to address ‘btm’.
-Select * from Student where address <> ‘btm,;
44. Write SQL query to display the location of ‘Ram’.
-Select address from student where name=’Ram’;
45. Write SQL query to display the total information of student table along with name and location of all the
students having address ‘Birtamode’.
-Select * from Student where address=’Birtamode’;
46. Create table below with appropriate data type and constraints. Employee Emp_Id Name Address Salary
Dept_Id Department Dept_Id Dept_Name Floor
-Create table employee (
Emp_id int primary key not null,
Name Varchar(200),
Address varchar(200),
Salary int,
Dept_Id int );
48. Select name and address of employees whose salary is between 10000 and 20000.
-Select name, address from employees where salary between 10000 and 20000;
49. Select employee id, employee name and department name of employees working in first floor.
-Select eid,ename,depname from employees where floor=’frist’;
50. Select all records of department which are in second floor.
-Select * from department where floor=’second’;
51. Select name, address and department name of employees which are from Birtamode.
-Select name,address,depname from employees where address=’Birtamode’;
52. Select employee id and name of employees having salary more than 10000 and from Kathmandu.
-Select employee id,name from employee where salary >10000 and address=’Kathmandu’;
53. Select name, department name and floor of employee whose name start with letter ‘R’ and age is greater
than 30.
-Select name, depname, floor from employee where name like(‘R%’) and age >30;
54. Select employee id and department name of employees whose floor is ‘first’ by arranging in ascending
order on the basis of salary.
-select employee id, depname from employees where floor=’first’ order by salary asc;
55. Select total number of employee working in each department.
-Select count(emp_id) from department;
56. Select maximum salary of employee working in each floor and whose department is ‘Finance’.
-Select max(salary) from
57. Select name and department name of employees whose salary is greater than average salary of all
employees.
-Select name, depname from employees where salary> (select avg(Salary)from employee);
58. Select name and address of employee where salary is between 20000 and 30000 and floor is ‘second’.
-Select name, address from employee where salary between 20000 and 30000 and floor=’Second’;
59. Select name and department name employee whose age is minimum.
-Select name,depname from employee where age=(select min(age) from employee);
60. Select sum of salary of all employees whose name ends with letter ‘s’ and department is ‘Account’
-Select sum(salary) from employee where name like(%s) and depname=’Account’;