Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.27 MySQL Community Server - GPL
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| 4mt21ai017_library |
| cs050 |
| information_schema |
| library |
| mysql |
| orders |
| performance_schema |
| sakila |
| sys |
| world |
+--------------------+
10 rows in set (0.01 sec)
mysql> use 4mt21ai017_library;
Database changed
mysql> show tables;
+------------------------------+
| Tables_in_4mt21ai017_library |
+------------------------------+
| book |
| book_authors |
| book_copies |
| book_lending |
| card |
| library_programme |
| pub_year |
| publisher |
+------------------------------+
8 rows in set (0.01 sec)
mysql> select * from book lending;
+---------+-------------------+--------------------+-------------+
| book_id | title | publisher_name | pub_year |
+---------+-------------------+--------------------+-------------+
| 101 | 2 States | Arihant publishers | 19 May 2017 |
| 102 | Godaan | Bandup books | 10 Jan 2017 |
| 104 | Screwed by Murder | Penguin books | 6 Aug 2017 |
| 105 | Merry Christmas | Xpert books | 17 Dec 2022 |
+---------+-------------------+--------------------+-------------+
4 rows in set (0.02 sec)
mysql>
mysql> desc book;
+----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+-------------+------+-----+---------+-------+
| book_id | int | NO | PRI | NULL | |
| title | varchar(20) | YES | | NULL | |
| publisher_name | varchar(25) | YES | MUL | NULL | |
| pub_year | varchar(20) | YES | | NULL | |
+----------------+-------------+------+-----+---------+-------+
4 rows in set (0.01 sec)
mysql> select * from book;
+---------+-------------------+--------------------+-------------+
| book_id | title | publisher_name | pub_year |
+---------+-------------------+--------------------+-------------+
| 101 | 2 States | Arihant publishers | 19 May 2017 |
| 102 | Godaan | Bandup books | 10 Jan 2017 |
| 104 | Screwed by Murder | Penguin books | 6 Aug 2017 |
| 105 | Merry Christmas | Xpert books | 17 Dec 2022 |
+---------+-------------------+--------------------+-------------+
4 rows in set (0.00 sec)
mysql> select * from book_authors;
+---------+-----------------+
| book_id | author_name |
+---------+-----------------+
| 101 | Chetan Bhagat |
| 102 | Premchand |
| 104 | Saurabh Katyal |
| 105 | Sriram Raghavan |
+---------+-----------------+
4 rows in set (0.01 sec)
mysql> select * from book_copies;
+---------+--------------+--------------+
| book_id | programme_id | no_of_copies |
+---------+--------------+--------------+
| 101 | 1 | 5260 |
| 102 | 2 | 4896 |
| 104 | 4 | 6875 |
| 105 | 5 | 7896 |
+---------+--------------+--------------+
4 rows in set (0.01 sec)
mysql> select * from book lending;
+---------+-------------------+--------------------+-------------+
| book_id | title | publisher_name | pub_year |
+---------+-------------------+--------------------+-------------+
| 101 | 2 States | Arihant publishers | 19 May 2017 |
| 102 | Godaan | Bandup books | 10 Jan 2017 |
| 104 | Screwed by Murder | Penguin books | 6 Aug 2017 |
| 105 | Merry Christmas | Xpert books | 17 Dec 2022 |
+---------+-------------------+--------------------+-------------+
4 rows in set (0.00 sec)
mysql> select * from card;
+---------+
| card_id |
+---------+
| 2001 |
| 2002 |
| 2003 |
| 2004 |
| 2005 |
+---------+
5 rows in set (0.01 sec)
mysql> select* from library programme;
ERROR 1146 (42S02): Table '4mt21ai017_library.library' doesn't exist
mysql> select* from library_programme;
+--------------+----------------+------------------+
| programme_id | programme_name | address |
+--------------+----------------+------------------+
| 1 | Rom-com | Mumbai |
| 2 | Folk-lore | Varanasi |
| 3 | Biography | Assam |
| 4 | Crome-thriller | Himachal Pradesh |
| 5 | Dark-comedy | Kerala |
+--------------+----------------+------------------+
5 rows in set (0.01 sec)
mysql> select * from pub_year;
+-------------+
| pub_year |
+-------------+
| 19 May 2017 |
| 10 Jan 2017 |
| 6 Aug 2017 |
| 17 Dec 2022 |
+-------------+
4 rows in set (0.00 sec)
mysql> select * from publisher;
+--------------------+--------------------------+------------+
| name | address | phone |
+--------------------+--------------------------+------------+
| Arihant publishers | Jai-colony Uttar-Pradesh | 8976589645 |
| Bandup books | Raniganj villa Udgaon | 7895469856 |
| Geeko books | Andhadhun complex,Bandra | 7760069856 |
| Penguin books | 18-Rani-penthouse Kasoli | 9876548698 |
| Xpert books | Freddy colony,ooty | 8795645689 |
+--------------------+--------------------------+------------+
5 rows in set (0.01 sec)
mysql> select * from book_lending;
+---------+--------------+---------+------------+------------+
| book_id | programme_id | card_id | date_out | due_date |
+---------+--------------+---------+------------+------------+
| 101 | 1 | 2001 | 14jan2017 | 20jan2017 |
| 102 | 2 | 2002 | 10feb2023 | 20marc2023 |
| 104 | 4 | 2004 | 20marc2017 | 2apr2017 |
| 105 | 5 | 2005 | 20may2018 | 2june2018 |
+---------+--------------+---------+------------+------------+
4 rows in set (0.02 sec)
mysql> insert into book_lending values(103,3,2003,"5feb2017","28feb2017");
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint
fails (`4mt21ai017_library`.`book_lending`, CONSTRAINT `book_lending_ibfk_1`
FOREIGN KEY (`book_id`) REFERENCES `book` (`book_id`) ON DELETE CASCADE)
mysql> desc book_lending;
+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| book_id | int | NO | PRI | NULL | |
| programme_id | int | NO | PRI | NULL | |
| card_id | int | NO | PRI | NULL | |
| date_out | varchar(20) | YES | | NULL | |
| due_date | varchar(20) | YES | | NULL | |
+--------------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
mysql> update book_lending set card_id=1 where book_id=
->
->
->
->
->
->
->
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '' at
line 1
mysql> update book_lending set card_id=2001 where book_id=102;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update book_lending set card_id=2001 where book_id=104;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update book_lending set card_id=2001 where book_id=105;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from book_lending;
+---------+--------------+---------+------------+------------+
| book_id | programme_id | card_id | date_out | due_date |
+---------+--------------+---------+------------+------------+
| 101 | 1 | 2001 | 14jan2017 | 20jan2017 |
| 102 | 2 | 2001 | 10feb2023 | 20marc2023 |
| 104 | 4 | 2001 | 20marc2017 | 2apr2017 |
| 105 | 5 | 2001 | 20may2018 | 2june2018 |
+---------+--------------+---------+------------+------------+
4 rows in set (0.00 sec)
mysql> update book_lending set date_out=10feb2023 where book_id=102;
ERROR 1054 (42S22): Unknown column '10feb2023' in 'field list'
mysql> update book_lending set date_out="10feb2023" where book_id=102;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
mysql> update book_lending set due_date="20marc2023" where book_id=102;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
mysql> update book_lending set date_out="10feb2017" where book_id=102;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update book_lending set due_date="22marc2017" where book_id=102;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update book_lending set due_date="25marc2017" where book_id=105;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update book_lending set date_out="16feb2017" where book_id=102;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from book_lending;
+---------+--------------+---------+------------+------------+
| book_id | programme_id | card_id | date_out | due_date |
+---------+--------------+---------+------------+------------+
| 101 | 1 | 2001 | 14jan2017 | 20jan2017 |
| 102 | 2 | 2001 | 16feb2017 | 22marc2017 |
| 104 | 4 | 2001 | 20marc2017 | 2apr2017 |
| 105 | 5 | 2001 | 20may2018 | 25marc2017 |
+---------+--------------+---------+------------+------------+
4 rows in set (0.00 sec)
mysql> update book_lending set date_out="6feb2017" where book_id=105;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from book_lending;
+---------+--------------+---------+------------+------------+
| book_id | programme_id | card_id | date_out | due_date |
+---------+--------------+---------+------------+------------+
| 101 | 1 | 2001 | 14jan2017 | 20jan2017 |
| 102 | 2 | 2001 | 16feb2017 | 22marc2017 |
| 104 | 4 | 2001 | 20marc2017 | 2apr2017 |
| 105 | 5 | 2001 | 6feb2017 | 25marc2017 |
+---------+--------------+---------+------------+------------+
4 rows in set (0.00 sec)
mysql> select card_id from book_lending when due_date="jan2017" and "june2017"
geoup card_id having count(*)>3;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'when
due_date="jan2017" and "june2017" geoup card_id having count(*)>3' at line 1
mysql> select card_id from book_lending when due_date between "jan2017" and
"june2017" geoup card_id having count(*)>3;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'when
due_date between "jan2017" and "june2017" geoup card_id having count(*)>3' at line
1
mysql> select card_id from book_lending when due_date between "jan2017" and
"june2017" geoup card_id is having count(*)>3;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'when
due_date between "jan2017" and "june2017" geoup card_id is having count(*)>' at
line 1
mysql> select card_id from book_lending where due_date between "jan2017" and
"june2017" geoup card_id is having count(*)>3;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'geoup
card_id is having count(*)>3' at line 1
mysql> select card_id from book_lending where due_date between "01jan2017" and
"01june2017" geoup card_id is having count(*)>3;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'geoup
card_id is having count(*)>3' at line 1
mysql> select card_id from book_lending where due_date between "01jan2017" and
"01june2017" group by card_id having count(*)>3;
Empty set (0.00 sec)
mysql> select card_id from book_lending where due_date between "01jan2017" and
"01june2017" group by card_id having count(*)>2;
Empty set (0.00 sec)
mysql> select card_id from book_lending where due_date between "01jan2017" and
"01june2017" group by card_id having count(*)>4;
Empty set (0.00 sec)
mysql> select card_id from book_lending where due_date between "01jan2017" and
"01june2017" group by card_id having count(*)>1;
Empty set (0.00 sec)
mysql> select card_id from book_lending where due_date between "01jan2017" and
"01june2017" group by card_id having count(*)>1;
Empty set (0.00 sec)
mysql> select card_id from book_lending where due_date between "14jan2017" and
"16june2017" group by card_id having count(*)>1;
Empty set (0.00 sec)
mysql> select card_id from book_lending where due_date between "14jan2017" and
"16june2017" group by card_id having count(*)>0;
Empty set (0.00 sec)
mysql> select card_id from book_lending where due_date between "14jan2017" and
"16feb2017" group by card_id having count(*)>0;
Empty set (0.00 sec)
mysql> select card_id from book_lending where due_date between "14jan2017" and
"6feb2017" group by card_id having count(*)>0;
+---------+
| card_id |
+---------+
| 2001 |
+---------+
1 row in set (0.00 sec)
mysql>
mysql>
;l