Question: Why is my code not outputting results? CREATE TEMP TABLE clean _ data AS SELECT product _ id , COALESCE ( product _ type, 'Unknown'

Why is my code not outputting results? CREATE TEMP TABLE clean_data AS
SELECT
product_id,
COALESCE(product_type, 'Unknown') AS product_type,
COALESCE(brand, 'Unknown') AS brand,
(SELECT ROUND(AVG(COALESCE(NULLIF(substring(weight::text, '[0-9]+[.]?[0-9]*'),''),'0')::NUMERIC),2)
FROM (
SELECT weight,
ROW_NUMBER() OVER (ORDER BY COALESCE(NULLIF(substring(weight::text, '[0-9]+[.]?[0-9]*'),''),'0')::NUMERIC) AS row_num,
COUNT(*) OVER () AS total_rows
FROM products
WHERE weight::text ~ '[0-9]+[.]?[0-9]*'
) AS sub1
WHERE row_num IN ((total_rows +1)/2,(total_rows +2)/2)
) AS weight_median,
(SELECT ROUND(AVG(COALESCE(NULLIF(substring(price::text, '[0-9]+[.]?[0-9]*'),''),'0')::NUMERIC),2)
FROM (
SELECT price,
ROW_NUMBER() OVER (ORDER BY COALESCE(NULLIF(substring(price::text, '[0-9]+[.]?[0-9]*'),''),'0')::NUMERIC) AS row_num,
COUNT(*) OVER () AS total_rows
FROM products
WHERE price::text ~ '[0-9]+[.]?[0-9]*'
) AS sub2
WHERE row_num IN ((total_rows +1)/2,(total_rows +2)/2)
) AS price_median,
COALESCE(average_units_sold, 0) AS average_units_sold,
COALESCE(year_added, 2022) AS year_added,
COALESCE(stock_location, 'Unknown') AS stock_location
FROM products;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!