解答
149
SQL文(クエリ)
WITH master AS (
SELECT
product_id
, SUM(revenue) / SUM(quantity) AS avg_unit_price_1
FROM
sample.sales
WHERE
product_id = 1
GROUP BY
product_id
)
, master2 AS (
SELECT
SUM(revenue) / SUM(quantity) AS avg_unit_price_all
FROM
sample.sales
)
SELECT
avg_unit_price_1
, avg_unit_price_all
, avg_unit_price_1 / avg_unit_price_all AS diff_percent
FROM
master
CROSS JOIN master2



