0% found this document useful (0 votes)
13 views4 pages

SQL Practice: Library & Football Queries

The document contains a set of SQL query practice questions and solutions for two databases: a Library Information System (LIS) and a Football League Information System (FLIS). Each system has 15 questions focusing on data retrieval related to students, books, teams, and matches. The solutions provide SQL queries for each question to demonstrate how to extract the required information from the respective databases.

Uploaded by

24f1002200
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)
13 views4 pages

SQL Practice: Library & Football Queries

The document contains a set of SQL query practice questions and solutions for two databases: a Library Information System (LIS) and a Football League Information System (FLIS). Each system has 15 questions focusing on data retrieval related to students, books, teams, and matches. The solutions provide SQL queries for each question to demonstrate how to extract the required information from the respective databases.

Uploaded by

24f1002200
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

SQL Query Practice - Library and Football League Databases

Library Information System (LIS) - 15 Questions

1. Retrieve the names of all students along with their department names.

2. Find the total number of books issued by each member.

3. List all books that have never been issued.

4. Retrieve the names of authors who have written more than 5 books.

5. Get the student details who have issued the maximum number of books.

6. Find the total number of books issued in the current year.

7. Retrieve the names of all faculty members who have never issued a book.

8. List all books along with the number of copies available.

9. Find the most frequently issued book.

10. Retrieve the names of members who have issued books beyond their allowed quota.

11. Get the details of books issued but not yet returned.

12. Retrieve the details of the department having the highest number of students.

13. Find students who have never issued a book.

14. List all members and their maximum allowed book quota.

15. Find the total number of books issued by each department.

Football League Information System (FLIS) - 15 Questions

16. Retrieve the names of all teams and their cities.

17. Find the total number of matches played by each team.

18. List the referees who have officiated more than 5 matches.

19. Get the details of the team that has won the most matches.

20. Find all matches where the host team scored more than 3 goals.

21. Retrieve the names of players who have played in more than 10 matches.

22. Find teams that have never lost a match.

23. Get the details of referees who have never officiated a match.

24. Retrieve the names of players along with their teams.


25. List the managers who have been managing their team for more than 5 years.

26. Find teams that have both home and away jersey colors the same.

27. Retrieve all match details where the guest team won.

28. Find the player who has played for the maximum number of teams.

29. Get the details of matches where the score difference is 2 or more.

30. Find the youngest player in the league.


SQL Solutions

Library Information System (LIS) - Solutions

1. SELECT s.student_fname, s.student_lname, d.department_name FROM students s JOIN


departments d ON s.department_code = d.department_code;

2. SELECT member_no, COUNT(*) AS total_books_issued FROM book_issue GROUP BY


member_no;

3. SELECT * FROM book_catalogue WHERE ISBN_no NOT IN (SELECT ISBN_no FROM


book_copies WHERE accession_no IN (SELECT accession_no FROM book_issue));

4. SELECT author_fname, author_lname, COUNT(*) AS book_count FROM book_authors GROUP


BY author_fname, author_lname HAVING COUNT(*) > 5;

5. SELECT member_no, COUNT(*) AS issued_books FROM book_issue GROUP BY member_no


ORDER BY issued_books DESC LIMIT 1;

6. SELECT COUNT(*) FROM book_issue WHERE YEAR(doi) = YEAR(CURRENT_DATE());

7. SELECT f.faculty_fname, f.faculty_lname FROM faculty f LEFT JOIN members m ON [Link] = [Link]
LEFT JOIN book_issue b ON m.member_no = b.member_no WHERE b.member_no IS NULL;

8. SELECT c.ISBN_no, COUNT(*) AS copies_available FROM book_copies c LEFT JOIN


book_issue b ON c.accession_no = b.accession_no WHERE b.accession_no IS NULL GROUP BY
c.ISBN_no;

9. SELECT accession_no, COUNT(*) AS issue_count FROM book_issue GROUP BY accession_no


ORDER BY issue_count DESC LIMIT 1;

10. SELECT member_no FROM book_issue GROUP BY member_no HAVING COUNT(*) >
(SELECT max_books FROM quota WHERE member_type = (SELECT member_type FROM
members WHERE members.member_no = book_issue.member_no));

Football League Information System (FLIS) - Solutions

16. SELECT name, city FROM teams;

17. SELECT team_id, COUNT(*) AS matches_played FROM matches GROUP BY team_id;

18. SELECT referee, COUNT(*) AS matches_officiated FROM match_referees GROUP BY referee


HAVING COUNT(*) > 5;

19. SELECT host_team_id, COUNT(*) AS wins FROM matches WHERE host_team_score >
guest_team_score GROUP BY host_team_id ORDER BY wins DESC LIMIT 1;
20. SELECT * FROM matches WHERE host_team_score > 3;

21. SELECT [Link] FROM players p JOIN matches m ON p.team_id = m.host_team_id OR


p.team_id = m.guest_team_id GROUP BY [Link] HAVING COUNT(*) > 10;

22. SELECT team_id FROM teams WHERE team_id NOT IN (SELECT guest_team_id FROM
matches WHERE guest_team_score > host_team_score);

23. SELECT [Link] FROM referees r LEFT JOIN match_referees mr ON r.referee_id = [Link]
WHERE [Link] IS NULL;

24. SELECT [Link], [Link] FROM players p JOIN teams t ON p.team_id = t.team_id;

25. SELECT name FROM managers WHERE since <= DATE_SUB(CURRENT_DATE(),


INTERVAL 5 YEAR);

26. SELECT * FROM teams WHERE jersey_home_color = jersey_away_color;

27. SELECT * FROM matches WHERE guest_team_score > host_team_score;

Common questions

Powered by AI

To find referees who have never officiated a match, you can use: SELECT r.name FROM referees r LEFT JOIN match_referees mr ON r.referee_id = mr.referee WHERE mr.referee IS NULL . Understanding which referees have never officiated a match assists in balancing assignment workloads, assessing training needs, and ensuring that every referee gains experience, maintaining fairness and competency across the league.

The SQL query is: SELECT name FROM managers WHERE since <= DATE_SUB(CURRENT_DATE(), INTERVAL 5 YEAR). Manager tenure is an important metric as it might correlate with the team's stability and performance. Long-term managers can develop coherent strategies, have a profound understanding of their team dynamics, and build a legacy that attracts talent or sponsorships, enhancing team success.

To find teams with the same home and away jersey colors, the query is: SELECT * FROM teams WHERE jersey_home_color = jersey_away_color . This strategy might benefit teams by reducing costs and logistical complexity. However, it could pose drawbacks during away games where their colors might clash with the host team, potentially causing visibility issues and confusion for referees, players, and spectators.

To find students who have never issued a book, use the query: SELECT s.student_fname, s.student_lname FROM students s LEFT JOIN members m ON s.member_no = m.member_no LEFT JOIN book_issue b ON m.member_no = b.member_no WHERE b.member_no IS NULL . If students do not engage with library resources, it could imply a need for promoting library services or tailoring resources to student interests, indicating potential gaps in collection relevance or access issues.

The query to identify such players is: SELECT p.name FROM players p JOIN matches m ON p.team_id = m.host_team_id OR p.team_id = m.guest_team_id GROUP BY p.name HAVING COUNT(*) > 10 . Players involved consistently indicate reliability and skill, potentially highlighting them as key performers or leaders within their team. Their extensive participation could lead to enhanced teamwork, experience, and skill development, contributing significantly to their team’s overall success.

To retrieve the names of books that have never been issued, you can use the following SQL query: SELECT * FROM book_catalogue WHERE ISBN_no NOT IN (SELECT ISBN_no FROM book_copies WHERE accession_no IN (SELECT accession_no FROM book_issue)). This query identifies books by checking for ISBN numbers in the catalogue that do not appear in the book issue records. The absence of these books in issue records may indicate that they are either not in demand, not found appealing by library members, or the library's marketing efforts for these books are insufficient.

Use the query: SELECT department_code, SUM(total_books_issued) AS total_issued FROM (SELECT s.department_code, COUNT(*) AS total_books_issued FROM book_issue b JOIN members m ON b.member_no = m.member_no JOIN students s ON m.member_no = s.member_no GROUP BY s.department_code) derived GROUP BY department_code ORDER BY total_issued DESC LIMIT 1 . This data guides resource allocation and helps prioritize which departments require additional library support or tailored collections, linking library services directly with departmental needs.

To identify the department with the highest number of students, you can execute the following SQL query: SELECT department_code, COUNT(student_id) AS student_count FROM students GROUP BY department_code ORDER BY student_count DESC LIMIT 1 . This information is useful for resource allocation, as departments with more students might require more instructional resources or library materials. It can also guide university policies on class sizes, faculty recruitment, and budget distribution.

You can determine which team has never lost a match with the query: SELECT team_id FROM teams WHERE team_id NOT IN (SELECT guest_team_id FROM matches WHERE guest_team_score > host_team_score). This distinction matters as it highlights a team's defensive capabilities and consistency in performance. Such teams might have strong strategies or high team morale, becoming favorites for sponsorships and fan involvement.

The SQL query to find the most frequently issued book is: SELECT accession_no, COUNT(*) AS issue_count FROM book_issue GROUP BY accession_no ORDER BY issue_count DESC LIMIT 1 . Factors contributing to a book's popularity could include relevance to current academic curricula, recommendations by educators, the author's reputation, or high reviews from previous readers. Understanding these factors can help libraries optimize their collections.

You might also like