SQL Queries
SQL Queries
NOTE: Create and Insert queries are not given as it is already discussed
in the Class. Syntax is given for your reference
CREATE TABLE TABLE_NAME (ATTRIBUTE1 DATATYPE1,
ATTRIBUTE2 DATATYPE2, ……….. ATTRIBUTEn DATATYPEn);
d) List all the issues for the current date with student and Book names
e) Give a count of how many books have been bought by each student
select bookname
from book
where bookno in (select bookno
from iss_rec
where memno in (select memno
from membership
where studno in (select studno
from student where studno=5)));
PROJECT
c) Find the list of guide, who are guiding more than two student groups.
select guide_name,count(*)
from guide g, project1 p
where g.guide_no=p.guide_no
group by guide_name
having count(*)>1;
d) Find the list of project no, project name & name of guide, in domain of Data Base.
e) Create a view as student_project details that lists student name, project name and guide
name
SELECT ANAME
FROM AIRCRAFT A, EMPLOYEES E, CERTIFIED C
WHERE C.EID=E.EID AND C.AID=A.AID AND E.SALARY>80000;
d) For each pilot who is certified for more than three aircraft, find the eid and the maximum
cruising range of the aircraft that he (or she) is certified for.
e)Find the names of pilots whose salary is less than the price of the cheapest route from Los
Angeles to Honolulu.
SELECT MAX(SALARY)
FROM EMPLOYEES
WHERE SALARY NOT IN ( SELECT MAX(SALARY) FROM EMPLOYEES);
OR
SELECT MAX(SALARY)
FROM EMPLOYEES
WHERE SALARY <> ( SELECT MAX(SALARY) FROM EMPLOYEES);
FOR nth highest salary
SELECT *
FROM EMPLOYEES EMP1
WHERE (N-1) = ( SELECT COUNT(DISTINCT(EMP2.SALARY))
FROM EMPLOYEES EMP2
WHERE EMP2.SALARY > EMP1.SALARY);
COMPANY
c) Find the names and address of all employees who work on same department.
d) Retrieve a list of employees and the projects they are working on, ordered by department
and, within each department, ordered alphabetically by last name, then first name.
e) Create a view Dept_info that gives details of department name, Number of employees and
total salary of each employee.
select s.sname
from sailors s
where s.sid in (select r.sid
from reserves r
where r.bid=103);
OR
select s.sname
from sailors s
where exists (select * from reserves r where r.bid=103 and r.sid=s.sid);
f) Find the average age of sailors for each rating level that has at least two sailors.