'MySQL Error: This version of MySQL doesn't yet support 'IGNORE NULLS'
I am trying to join two tables on the product_id and date columns. The product_date_cross table contains all date and product_id combinations within a time range. The review data is only available for specific days. In order to fill the missing values of the average rating, I wish to populate the last available non-null value. I am trying to run the following query on MySQL database:
SELECT
pdc.productId AS product_id,
pdc.selected_date AS date,
rd.avg_rating,
COALESCE(
rd.standing_review_count,
MAX(rd.standing_review_count)
OVER (PARTITION BY pdc.productId ORDER BY pdc.selected_date ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW),
0
)
AS review_count,
COALESCE(
rd.standing_avg_rating ,
LAST_VALUE (rd.standing_avg_rating) IGNORE NULLS
OVER (PARTITION BY pdc.productId ORDER BY pdc.selected_date ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW),
-1
)
AS avg_rating
FROM product_date_cross pdc
LEFT JOIN review_data rd
ON ((pdc.productId = rd.productId) AND (pdc.selected_date = rd.review_date))
ORDER BY pdc.productId, pdc.selected_date
Everything is working fine except for the LAST_VALUE part. When I try using the IGNORE NULLS clause I get the following error:
SQL Error [1235] [42000]: This version of MySQL doesn't yet support 'IGNORE NULLS'
I checked the MySQL 8 documentation which suggests that this is the correct syntax for LAST_VALUE.
Is my query missing something? Or is there another way of getting the last populated average rating?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
