Consider following schema and write SQL statements for given queries using subqueries.Faculty (f_id, f_name, address, city, state, age, salary, d_id)Department (dep_id, d_name, course, location, sub_code, subject)Student (enrl_no, s_name, s_address, s_city, s_state, s_age, course, f_id, hobby)Create tables with Primary Key, foreign key constraints in given schemas.1) Display name of faculties and students who are not living in the same city.2) Find out how much amount is spent on faculties as their salary who are working in 'IT Engineering' Department.3) Display department name, course, subject code and subject of person who have enrolled as a student.4) Display id and name of faculty who are working in 'IT Engineering' department and have a salary more than Rs. 60000
Question
Consider following schema and write SQL statements for given queries using subqueries.Faculty (f_id, f_name, address, city, state, age, salary, d_id)Department (dep_id, d_name, course, location, sub_code, subject)Student (enrl_no, s_name, s_address, s_city, s_state, s_age, course, f_id, hobby)Create tables with Primary Key, foreign key constraints in given schemas.1) Display name of faculties and students who are not living in the same city.2) Find out how much amount is spent on faculties as their salary who are working in 'IT Engineering' Department.3) Display department name, course, subject code and subject of person who have enrolled as a student.4) Display id and name of faculty who are working in 'IT Engineering' department and have a salary more than Rs. 60000
Solution
Sure, here are the SQL statements for the given queries:
- Create tables with Primary Key, foreign key constraints in given schemas.
CREATE TABLE Faculty (
f_id INT PRIMARY KEY,
f_name VARCHAR(100),
address VARCHAR(100),
city VARCHAR(50),
state VARCHAR(50),
age INT,
salary DECIMAL(10,2),
d_id INT
);
CREATE TABLE Department (
dep_id INT PRIMARY KEY,
d_name VARCHAR(100),
course VARCHAR(100),
location VARCHAR(100),
sub_code VARCHAR(50),
subject VARCHAR(100)
);
CREATE TABLE Student (
enrl_no INT PRIMARY KEY,
s_name VARCHAR(100),
s_address VARCHAR(100),
s_city VARCHAR(50),
s_state VARCHAR(50),
s_age INT,
course VARCHAR(100),
f_id INT,
hobby VARCHAR(100),
FOREIGN KEY (f_id) REFERENCES Faculty(f_id)
);
- Display name of faculties and students who are not living in the same city.
SELECT f_name, s_name
FROM Faculty, Student
WHERE Faculty.city != Student.s_city;
- Find out how much amount is spent on faculties as their salary who are working in 'IT Engineering' Department.
SELECT SUM(salary)
FROM Faculty
WHERE d_id IN (SELECT dep_id FROM Department WHERE d_name = 'IT Engineering');
- Display department name, course, subject code and subject of person who have enrolled as a student.
SELECT d_name, course, sub_code, subject
FROM Department
WHERE dep_id IN (SELECT d_id FROM Faculty WHERE f_id IN (SELECT f_id FROM Student));
- Display id and name of faculty who are working in 'IT Engineering' department and have a salary more than Rs. 60000
SELECT f_id, f_name
FROM Faculty
WHERE salary > 60000 AND d_id IN (SELECT dep_id FROM Department WHERE d_name = 'IT Engineering');
Similar Questions
Consider following schema and write query for given statementEmp (eid,ename,city,dname,salary) Project(eid,pid,pname,location)Create tables with Primary Key, foreign key constraints in given schemas.(1) Display name of employees who belongs to Computer department.(2) Display employee id whose name starts from letter J.(3) Display all details of employees whose salary is from 10000 to 20000.(4) Display name of employees who are having maximum salary.(5) Display name of employees whose salary is higher than average salary of the employee.(6) Display name of employees whose project id is 3 and location is Mumbai
Consider these following tables and only solve the query. Tables: 1) student: s_no (primary key), student_name, course_no (foreign key), age 2) courser-course-no (primary key), course-name.
Write a SQL query considering below schema. Create tables with Primary Key, foreign key constraints in given schemas.Manager (mid, eid, mname)Department (did, mid, dname, location)Employee (eid, ename, mobile, salary, joining_date, mid)i.Give the name and salary of employees whose salary are greater than each and every employees who are working under managerid 14.ii.Give the name of employees who have not assigned any department.iii.Give the employee names whose location is Kota.iv.Give the name of manager along with count of employees assigned to him/her in descending order
Consider following schema and write SQL for given statements.Student (RollNo, Name, DeptCode, City)Department (DeptCode, DeptName)Result (RollNo, Semester, SPI)1. List out the RollNo, Name along with SPI of Student.2. Display student name who got highest SPI in semester 1.3. Display the list of students whose DeptCode is 5, 6,7,10
Consider following schema and write SQL for given statements.Student (RollNo, Name, DeptCode, City), Department (DeptCode, DeptName), Result (RollNo, Semester, SPI)Create tables with Primary Key, foreign key constraints in given schemas.1)Retrieve all student names and their respective department names.2)Retrieve the average SPI (Semester Performance Index) for each student.3)Retrieve the students who have the highest SPI semester -wise.4)Retrieve the students who belong to a Ahmedabad city with their department names
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.