PRG NO.
4:
QUERY/OUTPUT:
TABLE CREATION: (TEACHER)
CREATE TABLE TEACHER(TID INT PRIMARY KEY, TNAME VARCHAR(15),
DEPT VARCHAR(15), GENDER CHAR(1), DOB DATE, EXPERIENCE INT);
TABLE CREATION: (SALARY)
CREATE TABLE SALARY(TID INT PRIMARY KEY, BASIC INT,
ALLOWANCE INT, DA INT);
RECORD INSERTION: (TEACHER)
INSERT INTO TEACHER VALUES (101, 'SIDDHARTH', 'ACCOUNTS',
'M', '1975-12-25', 12);
RECORD INSERTION: (SALARY)
INSERT INTO SALARY VALUES (101, 12000, 1000, 300);
TABLE SELECTION: (TEACHER)
SELECT * FROM TEACHER;
TABLE SELECTION: SALARY)
SELECT * FROM SALARY;
1
I GIVE QUERIES:
(i) SELECT * FROM TEACHER WHERE DEPT IN ('PHYSICS', 'CHEMISTRY')
AND GENDER='M';
(ii) SELECT COUNT(*), MAX(BASIC), MIN(BASIC) FROM SALARY;
(iii) SELECT TNAME, DEPT FROM TEACHER WHERE TNAME LIKE "%A%"
AND DEPT NOT IN ('PHYSICS');
(iv) SELECT TID, TNAME, EXPERIENCE FROM TEACHER ORDER
BY EXPERIENCE DESC;
(v) SELECT T.TID, TNAME, DEPT, GENDER, BASIC+ALLOWANCE+DA AS
GROSS_SALARY, BASIC*0.12 AS PF
FROM TEACHER T, SALARY S WHERE T.TID=S.TID;
2
(vi) CREATE TABLE FEMALE_STAFF AS (SELECT TNAME, DEPT,
BASIC+ALLOWANCE+DA AS SALARY FROM TEACHER, SALARY
WHERE TEACHER.TID=SALARY.TID AND GENDER ='F');
II GIVE OUTPUT:
(i) SELECT TNAME, DEPT FROM TEACHER T, SALARY S
WHERE T.TID=S.TID AND 5*DA > ALLOWANCE;
(ii) SELECT TNAME, DEPT, DOB FROM TEACHER WHERE DEPT IN
('ACCOUNTS', 'COMPUTER', 'PHYSICS') AND DOB BETWEEN
'1965-01-01' AND '1975-12-31';
(iii) SELECT COUNT(DISTINCT DEPT) AS NO_DEPTS,COUNT(TNAME) AS
NO_TEACHERS FROM TEACHER;
(iv) SELECT TNAME, DEPT "DEPARTMENT WITH MOST EXPERIENCED
TEACHER" FROM TEACHER WHERE EXPERIENCE = (SELECT
MAX(EXPERIENCE) FROM TEACHER);
3
PRG NO. 5:
QUERY/OUTPUT:
TABLE CREATION: (FACULTY)
CREATE TABLE FACULTY(FID INT PRIMARY KEY, FIRST_NAME
VARCHAR(15), LAST_NAME VARCHAR(15), HIRE_DATE DATE,
SALARY INT );
TABLE CREATION: (COURSES)
CREATE TABLE COURSES(CID CHAR(3) PRIMARY KEY, FID INT,
CNAME VARCHAR(25), FEES INT);
RECORD INSERTION: (FACULTY)
INSERT INTO FACULTY VALUES(102, 'AMIT', 'MISHRA', '1998-12-
10’, 12000);
RECORD INSERTION: (COURSES)
INSERT INTO COURSES VALUES ('C21', 102, 'GRID COMPUTING', 40000);
TABLE SELECTION: (FACULTY)
SELECT * FROM FACULTY;
TABLE SELECTION: (COURSES)
SELECT * FROM COURSES;
4
I GIVE QUERIES:
(i) SELECT * FROM FACULTY WHERE SALARY>12000;
(ii) SELECT * FROM COURSES WHERE FEES BETWEEN 15000
AND 50000;
(iii) UPDATE COURSES SET FEES = FEES+500
WHERE CNAME IN ('System Design', 'Human Biology');
(iv) SELECT CID, FACULTY.FID, CNAME, FEES
FROM FACULTY, COURSES
WHERE COURSES.FID = FACULTY.FID AND FIRST_NAME = 'Sulekha'
ORDER BY CNAME DESC;
(v) SELECT * FROM FACULTY WHERE FIRST_NAME LIKE 'R%';
5
(vi) SELECT FIRST_NAME, LAST_NAME, SALARY, CNAME, FEES
FROM FACULTY, COURSES
WHERE COURSES.FID = FACULTY.FID AND LAST_NAME LIKE '%A'
AND SALARY > 10000 AND HIRE_DATE > '2000-01-01';
II GIVE OUTPUT:
(i) SELECT COUNT(DISTINCT F_ID) FROM COURSES;
(ii) SELECT MIN(SALARY) FROM FACULTY, COURSES
WHERE COURSES.F_ID = FACULTY.F_ID;
(iii) SELECT COUNT(*), MAX(HIRE_DATE), MIN(FIRST_NAME)
FROM FACULTY, COURSES
WHERE SALARY >= 12000 OR FEES < 50000
AND COURSES.FID = FACULTY.FID;
(iv) SELECT * FROM FACULTY
WHERE HIRE_DATE BETWEEN '2001-01-01' AND '2005-12-31';