You are on page 1of 4

SQL FILE

1. Create a student table with the student id, name, and marks as
attributes where the student id is the primary key.
Ans.

create table student (studentid int(3) primary key, name


varchar(20) not null, marks decimal(5,2));
Output:

2. Insert the details of a new student in the above table.


Output:

3. Delete the details of a student in the above table.

Output:
4. Use the select command to get the details of the students
with marks more than 80.
Ans.
select * from student where marks>80;
Output:

5. Find the min, max, sum, and average of the marks in a student
marks table.
Ans.

select max(marks), min(marks), sum(marks) , avg(marks) from student;


Output:

6. Find the total number of customers from each country in the


table (customer ID, customerName, country) using group by.
Ans.

select country, count(customer_id) from customer group by country;


7. Write a SQL query to order the (student ID, marks) table in
descending order of the marks.
Ans.
select * from student order by marks desc;
Output:

13. Show the average salary for all the departments with
more than 3 people for a job.
Ans.

SELECT JOBID, AVG(SALARY) FROM EMPLOYEE, JOB


WHERE JOB.JOBID = EMPLOYEE.JOBID
GROUP BY JOBID
HAVING COUNT(JOBID) >=3;

14. Display only the jobs with maximum salary greater


than or equal to 300000.
Ans.
SELECT JOBTITLE, MAX(SALARY) FROM JOB
GROUP BY JOBTITLE
HAVING MAX(SALARY) >= 300000;
15. Find out number of employees having ‘Manager’ as
job.
Ans.

SELECT COUNT(JOBID) FROM EMPLOYEE, JOB


WHERE JOB.JOBID = EMPLOYEE.JOBID AND JOB.JOBTITLE LIKE ‘%manager
%’;
16. List the count of employee grouped by deptno. (table EMPL)
Ans.

SELECT JOBID, COUNT(EMPLID) FROM EMPLOYEE


GROUP BY JOBID;

17. List the sum of employees salaries grouped by


department. (table EMPL)
Ans.
SELECT JOBID, SUM(SALARY) FROM EMPLOYEE, JOB
WHERE JOB.JOBID = EMPLOYEE.JOBID
GROUP BY EMPLOYEE.JOBID;

18. List the maximum salary of employee grouped by


their department number.
Ans.
SELECT JOBID, MAX(SALARY) FROM EMPLOYEE, JOB
WHERE JOB.JOBID = EMPLOYEE.JOBID
GROUP BY EMPLOYEE.JOBID;

You might also like