SQL File
SQL File
Q1-Create a student table with the student id, name, and marks as attributes
where the student id is the primary key
create table student (student Id int(3) primary key, name varchar(20) not null,
marks decimal(5,2)); Output:
Q5-Find the min, max, sum, and average of the marks in a student marks table.
select max(marks), min(marks), sum(marks) , avg(marks) from student;
Output-
Q6-Find the total number of customers from each country in the table
(customer ID, customerName, country) using group by.
select country, count(customer_id) from customer group by country;
Q7-Write a SQL query to order the (student ID, marks) table in descending
order of the marks
select * from student order by marks desc;
Output-
Q13 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;
Q14 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;
Q15. 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%’;
QQ16. List the count of employee grouped by deptno. (table EMPL)
Ans: SELECT JOBID,
COUNT(EMPLID) FROM EMPLOYEE GROUP BY JOBID;
Q17. 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;
Q 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;