I am running the following query but can’t seem to get the datediff() filter to work. The query is executing successfully but even if I change the datediff() to different values I still get the same result.
SELECT project_id
, google_rank
, COALESCE(
( SELECT google_rank
FROM eig_ranking mi
WHERE mi.project_id = m.project_id
ORDER BY project_id limit 1
)
, 0) - google_rank AS movement
, keyword
, domain
FROM eig_ranking m
WHERE (DATEDIFF(rank_date, NOW())) / 7 <= 12
AND google_rank != 0
ORDER BY movement DESC
thanks for your replies. I figured it out. I am not sure if its a MYSQL bug or documentation fault but interchanging the variables in the datediff() function to DATEDIFF(NOW(), rank_date) makes it work fine for all my queries and the results are all correct