0% found this document useful (0 votes)
27 views5 pages

Cls12 SQL Lab 2024batch

The document provides examples of SQL queries to: 1. Create a LIBRARY database and BOOKS and ISSUED tables to store book and issued book data. 2. Write queries to display book names, authors, and prices by publisher; list book names by type; order books by price; increase book prices by publisher; and display book IDs, names and quantities issued. 3. Provide the output for queries counting books, finding the maximum priced book over a quantity, listing books by publisher, and counting publishers above a price.

Uploaded by

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

Cls12 SQL Lab 2024batch

The document provides examples of SQL queries to: 1. Create a LIBRARY database and BOOKS and ISSUED tables to store book and issued book data. 2. Write queries to display book names, authors, and prices by publisher; list book names by type; order books by price; increase book prices by publisher; and display book IDs, names and quantities issued. 3. Provide the output for queries counting books, finding the maximum priced book over a quantity, listing books by publisher, and counting publishers above a price.

Uploaded by

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

SQL Queries

Q13.
Q14. Create a Database LIBRARY.
1. Create a table BOOKs (book_id (PK), book_name, author_name,
publishers, price, type, qty)
2. Create a table ISSUED (issue_id, book_id (FK), quantity_issued )

Answer to be written on white page


Create Table Command:
Create table books (book_id varchar(20) primary key,
book_name varchar(20),author_name varchar(20),publishers
varchar(20), price int,type varchar(20),qty int);

Create table issued (book_id varchar(20), quantity_issued int , foreign


key(book_id) references books(bool_id);
Write the SQL queries –
i. To show Book name, Author name and Price of books of First Publ.
publishers.
select Book_name,Author_name, price from books where
Publishers =”EPB”;
ii. To list the names from books of Text type.
Select Book_name from books where type=”Text”;
iii. To display the names and price from books in ascending order.
Select Book_name, price from books order by price desc;
iv. To increase the price of all books of EPB publishers by 50.
update books set price= price+50 where publishers = “EPB”;
v. To display the Book_Id, Book_Name. and Quantity_Issued for all
books which have been issued.
Select Book_ID, Book_Name, Quantity_Issued from Books,Issued
where Books.Book_Id=Issued.Book_Id;
Write the Output of the following queries based on the above tables
i. SELECT COUNT(*) FROM BOOKS;

Count(*)
5
ii. SELECT MAX(PRICE) FROM BOOKS WHERE QUANTITY >=
15;
Max(price)

750`

iii. SELECT BOOK_NAME, AUTHOR_NAME FROM BOOKS


WHERE PUBLISHERS = “EPB”;
Book_name Author_name
Fast cook Latha Kapoor
My first c++ Brian & Brooke
iv. SELECT COUNT(DISTINCT PUBLISHERS) FROM BOOKS WHERE
PRICE >= 400;
Q15. Write the MYSQL Connectivity program in Python to
a. Create a database school
b. Create a table student with the specifications- Roll no integer, Name
Char (10), city char (20), dob varchar /in MYSQL and perform the
following operation.

c. SELECT COUNT (*), CITY FROM STUDENT GROUP BY CITY


HAVING COUNT (*)>1;

Output

(2, 'Chennai')
(3, 'Kolkata')
Q16. Integrate SQL with python by importing the MYSQL module
a. SELECTMAX (DOB), MIN (DOB) FROM STUDENT;
Ans:

Output
('12may23', '11apr23')

You might also like