1 | | незнам |
| 1 | == Извештај кој прикажува инструктори со највисок профит по месеци и години. |
| 2 | |
| 3 | {{{ |
| 4 | WITH InstructorProfit AS ( |
| 5 | SELECT |
| 6 | i.ID AS InstructorID, |
| 7 | EXTRACT(YEAR FROM p.Date) AS Year, |
| 8 | EXTRACT(MONTH FROM p.Date) AS Month, |
| 9 | SUM(p.Amount) AS TotalProfit |
| 10 | FROM |
| 11 | project.Payment p |
| 12 | INNER JOIN |
| 13 | project.Instructor i ON p.InstructorFK = i.ID |
| 14 | GROUP BY |
| 15 | i.ID, EXTRACT(YEAR FROM p.Date), EXTRACT(MONTH FROM p.Date) |
| 16 | ) |
| 17 | SELECT |
| 18 | ip.Year, |
| 19 | ip.Month, |
| 20 | u.FirstName || ' ' || u.LastName AS InstructorName, |
| 21 | ip.TotalProfit |
| 22 | FROM |
| 23 | InstructorProfit ip |
| 24 | INNER JOIN |
| 25 | project.Instructor i ON ip.InstructorID = i.ID |
| 26 | INNER JOIN |
| 27 | project.User u ON i.UserFK = u.ID |
| 28 | WHERE |
| 29 | (ip.InstructorID, ip.TotalProfit, ip.Year, ip.Month) IN ( |
| 30 | SELECT |
| 31 | ip2.InstructorID, |
| 32 | MAX(ip2.TotalProfit) AS MaxProfit, |
| 33 | ip2.Year, |
| 34 | ip2.Month |
| 35 | FROM |
| 36 | InstructorProfit ip2 |
| 37 | GROUP BY |
| 38 | ip2.Year, ip2.month, ip2.InstructorID |
| 39 | ) |
| 40 | ORDER BY |
| 41 | ip.TotalProfit DESC; |
| 42 | |
| 43 | |
| 44 | }}} |
| 45 | |
| 46 | == Извештај кој ни прикажува топ три најпопуларни типови на тренинзи според бројот на инструктори кои ги преферираат, каде што членовите имаат доделен инструктор. |
| 47 | |
| 48 | {{{ |
| 49 | SELECT |
| 50 | w.Type AS WorkoutType, |
| 51 | COUNT(*) AS InstructorPreferenceCount |
| 52 | FROM |
| 53 | project.Workout w |
| 54 | WHERE |
| 55 | EXISTS ( |
| 56 | SELECT 1 |
| 57 | FROM project.Member m |
| 58 | WHERE w.MemberFK = m.Id |
| 59 | AND m.InstructorFK IS NOT NULL |
| 60 | ) |
| 61 | GROUP BY |
| 62 | w.Type |
| 63 | ORDER BY |
| 64 | COUNT(*) DESC |
| 65 | LIMIT 3; |
| 66 | |
| 67 | }}} |
| 68 | |