| 11 | | SELECT |
| 12 | | cpu.brand AS cpu_brand, |
| 13 | | cpu.name AS cpu_model, |
| 14 | | mobo.chipset AS motherboard_chipset, |
| 15 | | b.id AS build_id, |
| 16 | | b.user_id |
| 17 | | FROM build b |
| 18 | | JOIN build_component bc_cpu ON b.id = bc_cpu.build_id |
| 19 | | JOIN components cpu ON bc_cpu.component_id = cpu.id |
| 20 | | JOIN build_component bc_mobo ON b.id = bc_mobo.build_id |
| 21 | | JOIN components mobo ON bc_mobo.component_id = mobo.id |
| 22 | | WHERE cpu.type = 'CPU' |
| 23 | | AND mobo.type = 'Motherboard' |
| 24 | | AND b.is_approved = TRUE |
| | 21 | SELECT |
| | 22 | cpu_comp.brand AS cpu_brand, |
| | 23 | cpu_comp.name AS cpu_model, |
| | 24 | mobo.chipset AS motherboard_chipset, |
| | 25 | b.id AS build_id, |
| | 26 | b.user_id, |
| | 27 | b.created_at |
| | 28 | FROM build b |
| | 29 | JOIN build_component bc_cpu ON b.id = bc_cpu.build_id |
| | 30 | JOIN components cpu_comp ON bc_cpu.component_id = cpu_comp.id |
| | 31 | JOIN cpu ON cpu.component_id = cpu_comp.id |
| | 32 | JOIN build_component bc_mobo ON b.id = bc_mobo.build_id |
| | 33 | JOIN components mobo_comp ON bc_mobo.component_id = mobo_comp.id |
| | 34 | JOIN motherboard mobo ON mobo.component_id = mobo_comp.id |
| | 35 | WHERE b.is_approved = TRUE |
| 26 | | pair_metrics AS ( |
| 27 | | SELECT |
| 28 | | cmp.cpu_brand, |
| 29 | | cmp.cpu_model, |
| 30 | | cmp.motherboard_chipset, |
| 31 | | COUNT(cmp.build_id) AS total_builds, |
| 32 | | AVG(rb.value) AS avg_satisfaction, |
| 33 | | COUNT(DISTINCT CASE WHEN ub.last_active >= CURRENT_DATE - INTERVAL '3 months' |
| 34 | | THEN cmp.build_id END) AS active_builds |
| 35 | | FROM cpu_mobo_pairs cmp |
| 36 | | LEFT JOIN rating_build rb ON cmp.build_id = rb.build_id |
| 37 | | LEFT JOIN user_builds ub ON cmp.build_id = ub.build_id |
| 38 | | GROUP BY cmp.cpu_brand, cmp.cpu_model, cmp.motherboard_chipset |
| 39 | | HAVING COUNT(cmp.build_id) >= 10 |
| 40 | | ) |
| | 37 | recent_activity AS ( |
| | 38 | SELECT DISTINCT build_id |
| | 39 | FROM review |
| | 40 | WHERE created_at >= CURRENT_DATE - INTERVAL '3 months' |
| | 41 | ), |
| | 42 | pair_metrics AS ( |
| | 43 | SELECT |
| | 44 | cmp.cpu_brand, |
| | 45 | cmp.cpu_model, |
| | 46 | cmp.motherboard_chipset, |
| | 47 | COUNT(DISTINCT cmp.build_id) AS total_builds, |
| | 48 | AVG(COALESCE(rb.value, 0)) AS avg_satisfaction, |
| | 49 | COUNT(DISTINCT ra.build_id) AS active_builds |
| | 50 | FROM cpu_mobo_pairs cmp |
| | 51 | LEFT JOIN rating_build rb ON cmp.build_id = rb.build_id |
| | 52 | LEFT JOIN recent_activity ra ON cmp.build_id = ra.build_id |
| | 53 | GROUP BY |
| | 54 | cmp.cpu_brand, |
| | 55 | cmp.cpu_model, |
| | 56 | cmp.motherboard_chipset |
| | 57 | HAVING COUNT(DISTINCT cmp.build_id) >= 2 |
| | 58 | ) |
| 42 | | CONCAT(cpu_brand, ' ', cpu_model) AS cpu_combo, |
| 43 | | motherboard_chipset, |
| 44 | | total_builds, |
| 45 | | ROUND(avg_satisfaction, 2) AS avg_satisfaction, |
| 46 | | ROUND( |
| 47 | | (avg_satisfaction / 5.0) * 0.6 + |
| 48 | | (CAST(active_builds AS DECIMAL) / total_builds) * 0.4, |
| 49 | | 3 |
| 50 | | ) AS success_rate |
| | 60 | CONCAT(cpu_brand, ' ', cpu_model) AS cpu_combo, |
| | 61 | motherboard_chipset, |
| | 62 | total_builds, |
| | 63 | ROUND(CAST(avg_satisfaction AS numeric), 2) AS avg_satisfaction, |
| | 64 | ROUND( |
| | 65 | CAST( |
| | 66 | (avg_satisfaction / 5.0) * 0.6 + |
| | 67 | (CAST(active_builds AS DECIMAL) / total_builds) * 0.4 |
| | 68 | AS numeric), |
| | 69 | 3 |
| | 70 | ) AS success_rate |