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

Assignment 3

A MySQL table named 'book' is created to store information about books, including fields like ISBN, book title, category, page count, price, and year of publication. Several records are inserted, and various queries are executed to retrieve specific data, such as books with a page count greater than 600, total price of books published in 1990, and books within a certain price range. The table is modified by renaming a column and deleting a record, resulting in a final count of four books in the table.

Uploaded by

Mrinmoy Pathak
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

Assignment 3

A MySQL table named 'book' is created to store information about books, including fields like ISBN, book title, category, page count, price, and year of publication. Several records are inserted, and various queries are executed to retrieve specific data, such as books with a page count greater than 600, total price of books published in 1990, and books within a certain price range. The table is modified by renaming a column and deleting a record, resulting in a final count of four books in the table.

Uploaded by

Mrinmoy Pathak
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

mysql> CREATE TABLE book (

-> ISBN VARCHAR(20) PRIMARY KEY,


-> book_name VARCHAR(255),
-> category VARCHAR(50),
-> page_count INT,
-> price DECIMAL(10, 2),
-> year_of_publication year
-> );
Query OK, 0 rows affected (0.01 sec)

mysql> desc book;


+---------------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+---------------+------+-----+---------+-------+
| ISBN | varchar(20) | NO | PRI | NULL | |
| book_name | varchar(255) | YES | | NULL | |
| category | varchar(50) | YES | | NULL | |
| page_count | int | YES | | NULL | |
| price | decimal(10,2) | YES | | NULL | |
| year_of_publication | year | YES | | NULL | |
+---------------------+---------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

mysql> -- Insert data for books


mysql> INSERT INTO book (ISBN, book_name, category, page_count, price,
year_of_publication)
-> VALUES
-> ('101', 'Book 1', 'Novel', 700, 250.99, 1990),
-> ('102', 'Book 2', 'Science Fiction', 450, 819.99, 2005),
-> ('103', 'Book 3', 'Language', 800, 412.99, 1985),
-> ('104', 'Book 4', 'Religious Book', 350, 209.99, 1990),
-> ('105', 'Book 5', 'History', 550, 409.99, 1992);
Query OK, 5 rows affected (0.00 sec)
Records: 5 Duplicates: 0 Warnings: 0

mysql> select * from book;


+------+-----------+-----------------+------------+--------+---------------------+
| ISBN | book_name | category | page_count | price | year_of_publication |
+------+-----------+-----------------+------------+--------+---------------------+
| 101 | Book 1 | Novel | 700 | 250.99 | 1990 |
| 102 | Book 2 | Science Fiction | 450 | 819.99 | 2005 |
| 103 | Book 3 | Language | 800 | 412.99 | 1985 |
| 104 | Book 4 | Religious Book | 350 | 209.99 | 1990 |
| 105 | Book 5 | History | 550 | 409.99 | 1992 |
+------+-----------+-----------------+------------+--------+---------------------+
5 rows in set (0.00 sec)

mysql> SELECT book_name, price


-> FROM book
-> WHERE page_count > 600;
+-----------+--------+
| book_name | price |
+-----------+--------+
| Book 1 | 250.99 |
| Book 3 | 412.99 |
+-----------+--------+
2 rows in set (0.00 sec)

mysql> SELECT ISBN, price


-> FROM book
-> WHERE category IN ('Novel', 'Language', 'Religious Book');
+------+--------+
| ISBN | price |
+------+--------+
| 101 | 250.99 |
| 103 | 412.99 |
| 104 | 209.99 |
+------+--------+
3 rows in set (0.00 sec)

mysql> -- Rename the column


mysql> ALTER TABLE book
-> CHANGE COLUMN book_name book_title VARCHAR(255);
Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> select * from book;


+------+------------+-----------------+------------+--------+---------------------+
| ISBN | book_title | category | page_count | price | year_of_publication |
+------+------------+-----------------+------------+--------+---------------------+
| 101 | Book 1 | Novel | 700 | 250.99 | 1990 |
| 102 | Book 2 | Science Fiction | 450 | 819.99 | 2005 |
| 103 | Book 3 | Language | 800 | 412.99 | 1985 |
| 104 | Book 4 | Religious Book | 350 | 209.99 | 1990 |
| 105 | Book 5 | History | 550 | 409.99 | 1992 |
+------+------------+-----------------+------------+--------+---------------------+
5 rows in set (0.00 sec)

mysql> SELECT SUM(price) AS total_price_1990


-> FROM book
-> WHERE year_of_publication = 1990;
+------------------+
| total_price_1990 |
+------------------+
| 460.98 |
+------------------+
1 row in set (0.00 sec)

mysql> SELECT *
-> FROM book
-> WHERE year_of_publication <> 1992
-> ORDER BY price ASC;
+------+------------+-----------------+------------+--------+---------------------+
| ISBN | book_title | category | page_count | price | year_of_publication |
+------+------------+-----------------+------------+--------+---------------------+
| 104 | Book 4 | Religious Book | 350 | 209.99 | 1990 |
| 101 | Book 1 | Novel | 700 | 250.99 | 1990 |
| 103 | Book 3 | Language | 800 | 412.99 | 1985 |
| 102 | Book 2 | Science Fiction | 450 | 819.99 | 2005 |
+------+------------+-----------------+------------+--------+---------------------+
4 rows in set (0.00 sec)

mysql> SELECT COUNT(*) AS total_books


-> FROM book;
+-------------+
| total_books |
+-------------+
| 5 |
+-------------+
1 row in set (0.00 sec)
mysql> SELECT book_title
-> FROM book
-> WHERE price BETWEEN 300 AND 800;
+------------+
| book_title |
+------------+
| Book 3 |
| Book 5 |
+------------+
2 rows in set (0.00 sec)

mysql> DELETE FROM book


-> WHERE ISBN = '102';
Query OK, 1 row affected (0.01 sec)

mysql> select * from book;


+------+------------+----------------+------------+--------+---------------------+
| ISBN | book_title | category | page_count | price | year_of_publication |
+------+------------+----------------+------------+--------+---------------------+
| 101 | Book 1 | Novel | 700 | 250.99 | 1990 |
| 103 | Book 3 | Language | 800 | 412.99 | 1985 |
| 104 | Book 4 | Religious Book | 350 | 209.99 | 1990 |
| 105 | Book 5 | History | 550 | 409.99 | 1992 |
+------+------------+----------------+------------+--------+---------------------+
4 rows in set (0.00 sec)

You might also like