Changes between Version 1 and Version 2 of PricetoPerformance


Ignore:
Timestamp:
01/29/26 03:50:23 (10 days ago)
Author:
233051
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • PricetoPerformance

    v1 v2  
    99
    1010{{{
     11CREATE OR REPLACE FUNCTION get_report_price_to_performance()
     12    RETURNS TABLE (
     13                      build_name TEXT,
     14                      cpu_model TEXT,
     15                      gpu_model TEXT,
     16                      total_price NUMERIC,
     17                      performance_score NUMERIC,
     18                      price_to_performance_index NUMERIC
     19                  )
     20    LANGUAGE sql
     21AS $$
    1122WITH cpu_per_build AS (
    12     SELECT 
     23    SELECT
    1324        b.id AS build_id,
    1425        c.name AS cpu_model,
     
    1627        cpu.base_clock
    1728    FROM build b
    18     JOIN build_component bc ON b.id = bc.build_id
    19     JOIN components c ON bc.component_id = c.id
    20     JOIN cpu ON c.id = cpu.component_id
    21     WHERE c.type = 'CPU'
     29             JOIN build_component bc ON b.id = bc.build_id
     30             JOIN components c ON bc.component_id = c.id
     31             JOIN cpu ON c.id = cpu.component_id
     32    WHERE LOWER(c.type) = LOWER('CPU')
    2233),
    23 gpu_per_build AS (
    24     SELECT
    25         b.id AS build_id,
    26         c.name AS gpu_model,
    27         gpu.vram
    28     FROM build b
    29     JOIN build_component bc ON b.id = bc.build_id
    30     JOIN components c ON bc.component_id = c.id
    31     JOIN gpu ON c.id = gpu.component_id
    32     WHERE c.type = 'GPU'
    33 )
    34 
    35 SELECT
     34     gpu_per_build AS (
     35         SELECT
     36             b.id AS build_id,
     37             c.name AS gpu_model,
     38             gpu.vram
     39         FROM build b
     40                  JOIN build_component bc ON b.id = bc.build_id
     41                  JOIN components c ON bc.component_id = c.id
     42                  JOIN gpu ON c.id = gpu.component_id
     43         WHERE LOWER(c.type) = LOWER('GPU')
     44     )
     45SELECT
    3646    b.name AS build_name,
    3747    cpu.cpu_model,
     
    4050    (cpu.cores * cpu.base_clock + gpu.vram * 100) AS performance_score,
    4151    ROUND(
    42         (cpu.cores * cpu.base_clock + gpu.vram * 100),
    43         4
     52            CAST(
     53                    (cpu.cores * cpu.base_clock + gpu.vram * 100) / NULLIF(b.total_price, 0)
     54                AS numeric),
     55            4
    4456    ) AS price_to_performance_index
    4557FROM build b
    46 JOIN cpu_per_build cpu ON b.id = cpu.build_id
    47 JOIN gpu_per_build gpu ON b.id = gpu.build_id
     58         JOIN cpu_per_build cpu ON b.id = cpu.build_id
     59         JOIN gpu_per_build gpu ON b.id = gpu.build_id
    4860WHERE b.total_price > 0
    4961ORDER BY price_to_performance_index DESC
    5062LIMIT 20;
     63$$;
    5164}}}
    5265