• Skip to primary navigation
  • Skip to content
  • Skip to footer
Thomas Ngo Thomas Ngo
  • Home
  • Journal
  • Tags
  • About

    Thomas Ngo

    Software Engineer

    • Stanton, California
    • Email
    • GitHub
    • Resume

    SQL problem - Average Selling Price

    February 10, 2024 less than 1 minute read

    Page Navigation

    • Problem
    • My Query

    Problem

    problem-1251

    My Query

    SELECT
        p.product_id,
        ROUND(IFNULL(SUM(units * price)/SUM(units), 0),2) as average_price
    FROM
        Prices as p
    LEFT JOIN
        UnitsSold as u
        ON
            p.product_id = u.product_id AND (u.purchase_date BETWEEN p.start_date AND p.end_date)
    GROUP BY
        p.product_id
    

    Tags: SQL

    Updated: February 10, 2024

    Share on

    Twitter Facebook LinkedIn
    Previous Next

    You may also enjoy

    Problem of The Day: Total Cost to Hire K Workers

    January 15, 2026 less than 1 minute read

    Problem Statement

    Problem of The Day: Maximum Subsequence Score

    January 14, 2026 1 minute read

    Problem Statement

    Problem of The Day: Smallest Number in Infinite Set

    January 13, 2026 less than 1 minute read

    Problem Statement

    Problem of The Day: Kth Largest Element in an Array

    January 12, 2026 less than 1 minute read

    Problem Statement

    • Follow:
    • GitHub
    • LinkedIn
    © 2026 Thomas Ngo.