0% found this document useful (0 votes)
5 views3 pages

SQL Queries Answers

The document outlines SQL queries for two parts: the first part focuses on an Employee table, providing queries to list employees based on specific criteria, find the second highest salary, and create views. The second part deals with Book, Store, and Stock tables, including queries to update book costs, find authors of books in a specific store, and calculate total book quantities in stores. Additionally, it includes an example of inserting a new book record.

Uploaded by

ameyparab1105
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

SQL Queries Answers

The document outlines SQL queries for two parts: the first part focuses on an Employee table, providing queries to list employees based on specific criteria, find the second highest salary, and create views. The second part deals with Book, Store, and Stock tables, including queries to update book costs, find authors of books in a specific store, and calculate total book quantities in stores. Additionally, it includes an example of inserting a new book record.

Uploaded by

ameyparab1105
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

SQL QUERIES BASED ON GIVEN SCHEMAS

--- Part 1: Employee Table ---

Employee(Emp_no, Emp_name, Emp_add, ph_no, email_id, salary)

i) List the employee whose employee number is 100.

SQL:

SELECT * FROM Employee

WHERE Emp_no = 100;

ii) List the Employee whose salary is between 50K to 1 Lac.

SQL:

SELECT * FROM Employee

WHERE salary BETWEEN 50000 AND 100000;

iii) List the Employees whose name starts with 'Ami'.

SQL:

SELECT * FROM Employee

WHERE Emp_name LIKE 'Ami%';

iv) Find 2nd highest salary of Employees.

SQL:

SELECT MAX(salary) AS Second_Highest_Salary

FROM Employee

WHERE salary < (SELECT MAX(salary) FROM Employee);


v) Create two views on employee table.

SQL:

CREATE VIEW Emp_Basic_Info AS

SELECT Emp_no, Emp_name, Emp_add FROM Employee;

CREATE VIEW Emp_Contact AS

SELECT Emp_no, ph_no, email_id FROM Employee;

--- Part 2: Book, Store, Stock Tables ---

Book(book_id, title, author, cost)

Store(store_no, city, state, inventory_val)

Stock(store_no, book_id, quantity)

i) Modify the cost of DBMS books by 10%

SQL:

UPDATE Book

SET cost = cost * 1.10

WHERE title = 'DBMS';

ii) Find the author of the books which are available in Mumbai store

SQL:

SELECT DISTINCT B.author

FROM Book B
JOIN Stock S ON B.book_id = S.book_id

JOIN Store ST ON S.store_no = ST.store_no

WHERE ST.city = 'Mumbai';

iii) Find the title of the most expensive book

SQL:

SELECT title

FROM Book

WHERE cost = (SELECT MAX(cost) FROM Book);

iv) Find the total quantity of books in each store

SQL:

SELECT store_no, SUM(quantity) AS total_quantity

FROM Stock

GROUP BY store_no;

v) Add a new record in Book

SQL:

INSERT INTO Book (book_id, title, author, cost)

VALUES (105, 'SQL Basics', 'John Doe', 450);

You might also like