| | 1 | = Complex DB Reports (SQL, Stored Procedures, Relational Algebra) = |
| | 2 | |
| | 3 | === Top Performing Components in Highly-Rated Builds === |
| | 4 | |
| | 5 | Report on which specific components appear most frequently in builds that have received a high average user rating (4.5 stars or higher) within the last year. |
| | 6 | |
| | 7 | SQL: |
| | 8 | |
| | 9 | {{{ |
| | 10 | SELECT |
| | 11 | c.type, |
| | 12 | c.brand, |
| | 13 | c.name, |
| | 14 | COUNT(bc.component_id) AS usage_count, |
| | 15 | AVG(rb.value) AS avg_build_rating |
| | 16 | FROM components c |
| | 17 | JOIN build_component bc ON c.id = bc.component_id |
| | 18 | JOIN build b ON bc.build_id = b.id |
| | 19 | JOIN rating_build rb ON b.id = rb.build_id |
| | 20 | WHERE b.created_at >= CURRENT_DATE - INTERVAL '1 year' |
| | 21 | GROUP BY c.type, c.brand, c.name |
| | 22 | HAVING avg_build_rating >= 4.5 |
| | 23 | ORDER BY usage_count DESC, avg_build_rating DESC |
| | 24 | LIMIT 20; |
| | 25 | }}} |
| | 26 | |
| | 27 | Relational algebra: |
| | 28 | |
| | 29 | {{{ |
| | 30 | λ_20( |
| | 31 | τ_{usage_count DESC, avg_build_rating DESC}( |
| | 32 | σ_{avg_build_rating ≥ 4.5}( |
| | 33 | γ_{c.type, c.brand, c.name; |
| | 34 | COUNT(bc.component_id)→usage_count, |
| | 35 | AVG(rb.value)→avg_build_rating |
| | 36 | }( |
| | 37 | σ_{b.created_at ≥ CURRENT_DATE - 1 year}( |
| | 38 | (((components c ⋈_{c.id=bc.component_id} build_component bc) |
| | 39 | ⋈_{bc.build_id=b.id} build b) |
| | 40 | ⋈_{b.id=rb.build_id} rating_build rb) |
| | 41 | ) |
| | 42 | ) |
| | 43 | ) |
| | 44 | ) |
| | 45 | ) |
| | 46 | }}} |