子查询导致INTERVAL 90天的问题

时间:2014-04-22 01:32:42

标签: date subquery

    $query = mysqli_query($connect,"SELECT * FROM `posts` WHERE `name` LIKE '%$search%' 
        OR (number IN (
            SELECT number FROM `posts` WHERE `name` LIKE '%$search%'
         AND `number` !='')
     )
order by date ASC LIMIT 100");

我应该在哪里插入这一行?我无法使用上述查询。 THX。

 && date>=DATE_SUB(CURDATE(), INTERVAL 90 DAY)

(返回的所有行必须是INTERVAL 90 DAY ...包括子查询部分)

1 个答案:

答案 0 :(得分:0)

$query = mysqli_query($connect,"SELECT * FROM `posts` WHERE `name` LIKE 'adam'
&& date>=DATE_SUB(CURDATE(), INTERVAL 90 DAY) 
OR (number IN (
    SELECT number FROM `posts` WHERE `name` LIKE 'adam'
AND `number` !='')
)

如果adam行超过90天,则不会返回任何结果。 但是,当adam行少于90天时,子查询行的结果可能会过期。

所以我尝试了这个,但仍然绕过子查询的日期检查:

 $query = mysqli_query($connect,"SELECT * FROM `posts` WHERE `name` LIKE 'adam'
&& date>=DATE_SUB(CURDATE(), INTERVAL 90 DAY) 
OR (number IN (
    SELECT number FROM `posts` WHERE `name` LIKE 'adam'
AND `number` !=''
&& date>=DATE_SUB(CURDATE(), INTERVAL 90 DAY) )
)