这是我的 MySQL 查询,我在这个查询中有一周的问题。我不知道如何将 IF 条件与WHERE
子句一起应用。
询问:
SELECT
*,
IFNULL((SELECT ur.user_rating FROM user_rating ur
WHERE ur.vid_id = v.id AND ur.user_id = '1000'),'NULL') AS user_rating
FROM videos v
WHERE WEEK(v.video_released_date) = WEEK(NOW())
AND
v.`is_done` = 1
ORDER BY v.admin_listing ASC;
我想要 OR(如何将这个条件与 where 子句一起应用?)
IF( WEEK(v.video_released_date) = WEEK(NOW()) , WEEK(NOW()) , WEEK(NOW())-1)
=
IF( WEEK(v.video_released_date) = WEEK(NOW()) , WEEK(NOW()) , WEEK(NOW())-1)
简报
如果视频发布日期已过且与本周不匹配,则适用前一周
我
当我像这样尝试自己时,他们将整个数据返回给我
SELECT
*,
IFNULL((SELECT ur.user_rating FROM user_rating ur
WHERE ur.vid_id = v.id AND ur.user_id = '1000'),'NULL') AS user_rating
FROM videos v
WHERE IF(WEEK(v.video_released_date) = WEEK(NOW()),WEEK(NOW()),WEEK(NOW())-1)
= IF(WEEK(v.video_released_date) = WEEK(NOW()),WEEK(NOW()),WEEK(NOW())-1)
AND
v.`is_done` = 1
ORDER BY v.admin_listing ASC;
我在这个查询中做错了什么?