100% found this document useful (1 vote)
736 views5 pages

Docx

The document contains 34 SQL queries with instructions to retrieve data from database tables containing book, member, and book issue information. It involves selecting, updating, filtering, sorting, and manipulating data using functions like REGEXP_REPLACE and REGEXP_SUBSTR to format and extract parts of strings.

Uploaded by

ymt1123
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
100% found this document useful (1 vote)
736 views5 pages

Docx

The document contains 34 SQL queries with instructions to retrieve data from database tables containing book, member, and book issue information. It involves selecting, updating, filtering, sorting, and manipulating data using functions like REGEXP_REPLACE and REGEXP_SUBSTR to format and extract parts of strings.

Uploaded by

ymt1123
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

Day # 2 Assignments

Task / Problems:

1) List all the books that are written by Author Loni and has price
less then 600.

A) SELECT * FROM BOOKS_506917 WHERE AUTHOR_NAME=LONI AND


COST < 600;

2) List the Issue details for the books that are not returned yet.
A) SELECT * FROM ISSUE_506917 WHERE RETURN_DATE IS NULL ;

3) Update all the blank return_date with 31-Dec-06 excluding


7005 and 7006.
A) UPDATE ISSUE_506917 SET RETURN_DATE='31-DEC-2017' WHERE
LIB_ISSUE_ID=7001;
UPDATE ISSUE_506917 SET RETURN_DATE='31-DEC-2017' WHERE
LIB_ISSUE_ID=7002;
UPDATE ISSUE_506917 SET RETURN_DATE='31-DEC-2017' WHERE
LIB_ISSUE_ID=7003;
UPDATE ISSUE_506917 SET RETURN_DATE='31-DEC-2017' WHERE
LIB_ISSUE_ID=7004;

4) List all the Issue details that have books issued for more then
30 days.

A) SELECT * FROM ISSUE_506917 WHERE (RETURN_DATE)-


(ISSUE_DATE)>30;

5) List all the books that have price in range of 500 to 750 and has
category as Database.
A)
FROM books_506917 WHERE cost BETWEEN 500 AND 750;

6) List all the books that belong to any one of the following
categories Science, Database, Fiction, Management.
A)
SELECT * FROM BOOKS_506917 WHERE category in ('Science',
'Database', 'Fiction','Management');

7) List all the members in the descending order of Penalty due on


them.
A)
SELECT * FROM member_506917 ORDER BY penalty_amount DESC;
8) List all the books in ascending order of category and
descending order of price.
A)
select * from books_506917 order by category asc,cost desc;

9) List all the books that contain word SQL in the name of the
book.
A)
select * from books_506917 where book_name like'%SQL%';

10) List all the members whose name starts with R or G and
contains letter I in it.
A)
SELECT * FROM MEMBER_506917 where MEMBER_NAME like'R%'OR
MEMBER_NAME LIKE'G%' AND MEMBER_NAME LIKE '%I%';

11) List the entire book name in Init cap and author in upper case
in the descending order of the book name.
A)
select initcap(author_name),upper(book_name) from books_506917
order by book_name desc;

12) List the Issue Details for all the books issue by member 101
with Issue_date and Return Date in following format. Monday,

July, 10, 2006.

SELECT TO_CHAR(ISSUE_date,
'DY/MON/DD/YYYY'),TO_CHAR(RETURN_DATE,'DY/MON/DD/YYYY')FROM
ISSUE_506917 WHERE LIB_ISSUE_ID=7001;

13) List the data in the book table with category data displayed as
D for Database, S for Science, R for RDBMS and O for all the

others.

A) select
category,decode(category,'database','D','rdbms','R','science','S','others','O')
as types from books_506917;

14) List all the members that became the member in the year 2006.
A) SELECT MEMBER_NAME FROM MEMBER_506917 WHERE
TO_CHAR(ACC_OPEN_DATE,'YY')=06;

15) List the Lib_Issue_Id, Issue_Date, Return_Date and No of days


Book was issued.
A) SELECT LIB_ISSUE_ID,ISSUE_DATE,RETURN_DATE,(RETURN_DATE-
ISSUE_DATE) AS NUMBER_OF_DAYS FROM ISSUE_506917;

16) Find the details of the member of the Library in the order of
their
joining the library.

A) select * from issue_506917 order by issue_date ;

17) Display the count of total no of books issued to Member 101.


A) SELECT SUM(MAX_BOOKS_ALLOWED) FROM MEMBER_506917 WHERE
MEMBER_ID=1 ;

18) Display the total penalty due for all the members.
A) select sum(penalty_amount) from member_506917 ;

19) Display the total no of members


A) SELECT COUNT(MEMBER_NAME) FROM MEMBER_506917;

20) Display the total no of books issued


A) SELECT COUNT(LIB_ISSUE_ID) FROM ISSUE_506917;

21) Display the average membership fees paid by all the members
A) SELECT AVG(FEES_PAID) FROM MEMBER_506917;

22) Display no of months between issue date and return date for all
issue
A) SELECT ROUND((RETURN_DATE-ISSUE_DATE)/30) FROM
ISSUE_506917;

23) Display the length of members name


A) SELECT LENGTH(MEMBER_NAME)AS LENGTH_OF_NAME FROM
MEMBER_506917;

24) Display the first 5 characters of membership_type for all


members
A) SELECT SUBSTR(MEMBERSHIP_TYPE,1,5) FROM MEMBER_506917;

25) Display the last day of the issue date


A) SELECT LAST_DAY(ISSUE_DATE) FROM ISSUE_506917;

26) Using the regular expression function select name of book


beginning with L
A) SELECT BOOK_NAME FROM BOOKS_506917 WHERE
REGEXP_LIKE(BOOK_NAME,'^L');

27) Using regular expression replace using the string


'We are driving south by south east', replace south by
North in the above string

A) SELECT REGEXP_REPLACE('We are driving south by south east','south','north')


FROM DUAL;

28) Display the member_name starting with R using regular expression

A) SELECT MEMBER_NAME FROM MEMBER_506917 WHERE


REGEXP_LIKE(MEMBER_NAME,'^R');

29) Display the Book_name containing word SQL using regular


expression

A) SELECT BOOK_NAME FROM BOOKS_506917 WHERE


REGEXP_LIKE(BOOK_NAME,'SQL');

30) Display the Author_name starting with "L" from first position using
regular expression

A) SELECT AUTHOR_NAME FROM BOOKS_506917 WHERE


REGEXP_LIKE(AUTHOR_NAME,'^L');

31) Display the member_name containing "Ga" from first to second


position using regular expression

A) SELECT MEMBER_NAME FROM MEMBER_506917 WHERE


REGEXP_LIKE(MEMBER_NAME,'^Ga');

32) Replace the book_name "Mastering SQL" with "Advanced SQL"


using regular expression

A) SELECT BOOK_NAME, REGEXP_REPLACE(BOOK_NAME,'Mastering


SQL','Advanced SQL') FROM BOOKS_506917;

33) Replace the author_name "Scott Urman" with "Scott K Urman"


using regular expression

A) SELECT AUTHOR_NAME, REGEXP_REPLACE(AUTHOR_NAME,'Scott


Urman','Scott R Urman') FROM BOOKS_506917;

34) Display the value of book_name from position 1 to 5 containing "G"


using the using regular expression

A) SELECT BOOK_NAME, REGEXP_SUBSTR(BOOK_NAME,'.....',1) FROM


BOOKS_506917 WHERE REGEXP_LIKE(BOOK_NAME,'G');

You might also like