| 3 | | * |
| | 3 | * Извештај за името на книгата која била најмногу пати разменета во текот на дадена година |
| | 4 | |
| | 5 | {{{ |
| | 6 | create view most_borrowed_book as |
| | 7 | |
| | 8 | with BookSwapCount as( |
| | 9 | select b.Title, extract(year from t.BorrowDate) as SwapYear, count(tb.BookId) as SwapCount |
| | 10 | from Transaction t join TransactionBook tb on t.TransactionId=tb.TransactionId |
| | 11 | join Book b on tb.BookId=b.BookId |
| | 12 | group by b.title, extract(year from t.borrowdate) |
| | 13 | ) |
| | 14 | select SwapYear, Title, SwapCount |
| | 15 | from BookSwapCount |
| | 16 | where SwapCount = ( |
| | 17 | select max(SwapCount) |
| | 18 | from BookSwapCount bsc |
| | 19 | where bsc.SwapYear = BookSwapCount.SwapYear |
| | 20 | ); |
| | 21 | |
| | 22 | }}} |
| | 23 | |
| | 24 | |
| | 25 | * Извештај за корисникот со најмал рејтинг за даден период |
| | 26 | |
| | 27 | {{{ |
| | 28 | create view worst_rated_user as |
| | 29 | |
| | 30 | with UserAverageRatings as ( |
| | 31 | select au.Username, avg(r.Rating) as AverageRating |
| | 32 | from AppUser au join Review r on au.UserId=r.ReceiverId |
| | 33 | where r.Date between '2025-01-01' and '2025-06-30' |
| | 34 | group by au.Username |
| | 35 | ) |
| | 36 | select Username, AverageRating |
| | 37 | from UserAverageRatings |
| | 38 | where AverageRating = ( |
| | 39 | select min(AverageRating) |
| | 40 | from UserAverageRatings |
| | 41 | ); |
| | 42 | }}} |