Id
Id
-- Creating Tables
CREATE TABLE Instructor (
ID INT(5),
Name VARCHAR(30),
Dept_name VARCHAR(20),
Salary INT(6)
);
-----------------------------------------------------------------------------------
------------------------------------------------------------------------------
ASSIGNMENT 2
-- (e) Display instructors from Physics department earning less than 90000
SELECT * FROM faculty_info WHERE department = 'Physics' AND salary < 90000;
-- (i) Display course titles from Comp Sci Department not having 3 credits
SELECT title FROM course WHERE department = 'Comp. Sci' AND credits <> 3;
-- (j) Display all columns of Course table sorted by department names in descending
order
SELECT * FROM course ORDER BY department DESC;
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------
ASSIGNMENT 3
-- (b) display instructors with name starting with 'k' and salary > 65000
select *
from faculty_info
where name like 'k%' and salary > 65000;
-- (b) display the dept_name and average salary paid to instructors of each
department
select department, avg(salary) as avg_salary
from faculty_info
group by department;
-- (c) display the id, name & department of the instructor drawing the highest
salary
select id, name, department
from faculty_info
where salary = (select max(salary) from faculty);
-- (e) display the total credits of all courses offered in comp.sci. department
select sum(credits) as total_credits
from course
where department = 'comp. sci.';
-- (f) display the number of instructors and total salary drawn by physics and
comp.sci. departments
select department, count(*) as instructor_count, sum(salary) as total_salary
from faculty_info
where department in ('physics', 'comp. sci.')
group by department;
-- (g) display the total credits of comp.sci. and biology departments from course
table
select department, sum(credits) as total_credits
from course
where department in ('comp. sci.', 'biology')
group by department;
-- (j) display the number of instructors of each department sorted in high to low
select department, count(*) as instructor_count
from faculty_info
group by department
order by instructor_count desc;
-- (l) display the name of departments having number of instructors less than 2
select department
from faculty_info
group by department
having count(*) < 2;
-- (n) display the dept_name that has paid total salary more than 50000
select department
from faculty_info
group by department
having sum(salary) > 50000;
-- (o) display the total budget for the building built by watson
select sum(budget) as total_budget
from department
where builder = 'watson';
-- (a) display your name with first letter being capital, where the entered name is
in lower case
select concat(upper(left('dinanath', 1)), lower(substring('dinanath', 2))) as
name_with_capital;
-- (d) display all the instructor names with its first letter in upper case
select concat(upper(left(name, 1)), lower(substring(name, 2))) as formatted_name
from faculty_info;
-- (e) list the department name of each instructor as a three letter code
select upper(left(department, 3)) as dept_code
from faculty_info;
-- (i) display the experience of each instructor in terms of years and months
select concat(timestampdiff(year, date_of_join, curdate()), ' years, ',
mod(timestampdiff(month, date_of_join, curdate()), 12), ' months') as experience
from faculty_info;
-- (l) display the value 94204.27348 truncated up to 2 digits after decimal point
select truncate(94204.27348, 2) as truncated_value;
-- (o) display the string “hello iter” in lower case with a column heading lower
case
select lower('HELLO ITER') as lower_case;
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------
ASSIGNMENT 4
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------------
ASSIGNMENT 5
-- (m) SELECT *
FROM BRANCH B
WHERE EXISTS (
SELECT 1
FROM LOAN L
WHERE L.BRANCH_CODE = B.BRANCH_CODE
);
-- (n) SELECT *
FROM LOAN L
WHERE NOT EXISTS (
SELECT 1
FROM INSTALLMENT I
WHERE I.LOAN_NO = L.LOAN_NO
);