Changes between Version 11 and Version 12 of Напредни извештаи од базата (SQL и складирани процедури)


Ignore:
Timestamp:
01/11/25 16:16:10 (4 days ago)
Author:
222039
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Напредни извештаи од базата (SQL и складирани процедури)

    v11 v12  
    2020}}}
    2121
    22 === Извештај за најпозајмени книги ===
     22=== Извештај за најпозајмени книги по тримесечие ===
    2323{{{#!sql
    24 SELECT book.CoverImage, book.Title, book.Genre, author.FirstName, author.LastName, COUNT(loan.LoanID) AS loan_count FROM book
     24SELECT
     25    book.CoverImage,
     26    book.Title,
     27    book.Genre,
     28    author.FirstName,
     29    author.LastName,
     30    EXTRACT(QUARTER FROM loan.LoanDate) AS quarter,
     31    COUNT(loan.LoanID) AS loan_count
     32FROM book
    2533INNER JOIN book_copies ON book.BookID = book_copies.BookID
    2634LEFT JOIN loan ON book_copies.CopyID = loan.BookCopyID
    2735INNER JOIN book_author ON book.BookID = book_author.BookID
    2836INNER JOIN author ON book_author.AuthorID = author.AuthorID
    29 GROUP BY book.BookID, book.Title, book.CoverImage, book.Genre, author.FirstName, author.LastName
    30 ORDER BY loan_count DESC LIMIT 5;
     37WHERE EXTRACT(QUARTER FROM loan.LoanDate) = 4  -- Change this number (1-4) for different quarters
     38GROUP BY
     39    book.BookID,
     40    book.Title,
     41    book.CoverImage,
     42    book.Genre,
     43    author.FirstName,
     44    author.LastName,
     45    EXTRACT(QUARTER FROM loan.LoanDate)
     46ORDER BY loan_count DESC
     47LIMIT 5;
    3148}}}
    3249
    33 === Извештај за најмалку позајмувани книги ===
     50=== Извештај за најмалку позајмувани книги по тримесечие ===
    3451{{{#!sql
    35 SELECT book.CoverImage, book.Title, book.Genre, author.FirstName, author.LastName, COUNT(loan.LoanID) AS loan_count FROM book
     52SELECT
     53    book.CoverImage,
     54    book.Title,
     55    book.Genre,
     56    author.FirstName,
     57    author.LastName,
     58    EXTRACT(QUARTER FROM loan.LoanDate) AS quarter,
     59    COUNT(loan.LoanID) AS loan_count
     60FROM book
    3661INNER JOIN book_copies ON book.BookID = book_copies.BookID
    3762LEFT JOIN loan ON book_copies.CopyID = loan.BookCopyID
    3863INNER JOIN book_author ON book.BookID = book_author.BookID
    3964INNER JOIN author ON book_author.AuthorID = author.AuthorID
    40 GROUP BY book.BookID, book.Title, book.CoverImage, book.Genre, author.FirstName, author.LastName
    41 ORDER BY loan_count ASC LIMIT 5;
     65WHERE EXTRACT(QUARTER FROM loan.LoanDate) = 4  -- Change this number (1-4) for different quarters
     66GROUP BY
     67    book.BookID,
     68    book.Title,
     69    book.CoverImage,
     70    book.Genre,
     71    author.FirstName,
     72    author.LastName,
     73    EXTRACT(QUARTER FROM loan.LoanDate)
     74ORDER BY loan_count ASC
     75LIMIT 5;
    4276}}}
    4377