Consider the table BOOKS with the following sample records: Table: BOOKSBOOKID…
2026
Consider the table BOOKS with the following sample records:
Table: BOOKS
BOOKID | BookTitle | Author | Price | Edition | PubID |
|---|---|---|---|---|---|
2026103 | Data Science | J P Singh | 350 | 2025 | P12 |
2026112 | Lets Python | Harpreet Kaur | 400 | 2026 | P12 |
2025125 | RDBMS | Gems Gomez | 300 | 2026 | P09 |
(Note: The table contains additional records.)
Write MySQL queries to perform the following operations:
(A) Display complete details of books published in the year 2025 or later.
(B) Display the average price of all books.
(C) Display the total number of books published in each year.
(D) Display the details of all books whose title contains the word “Python” anywhere in the BookTitle.
Attempted by 19 students.
Show answer & explanation
(A) Books Published in 2025 or Later
• Use WHERE condition on Edition
• Filter records ≥ 2025
SQL Query:
SELECT * FROM BOOKS
WHERE Edition >= 2025;
(B) Average Price of Books
• Use AVG() function
• Applied on Price column
SQL Query:
SELECT AVG(Price) AS Average_Price
FROM BOOKS;
(C) Total Books per Year
• Use COUNT() with GROUP BY
• Group by Edition
SQL Query:
SELECT Edition, COUNT(*) AS Total_Books
FROM BOOKS
GROUP BY Edition;
(D) Books with “Python” in Title
• Use LIKE operator
• % used for pattern matching
SQL Query:
SELECT * FROM BOOKS
WHERE BookTitle LIKE '%Python%';