首页 > 解决方案 > 在 WHERE 中添加 OR

问题描述

我有 SQL 查询:

SELECT
    p.ID,
    p.post_author,
    p.post_status,
    p.post_name,
    p.post_parent,
    p.post_type,
    p.post_date,
    p.post_date_gmt,
    p.post_modified,
    p.post_modified_gmt,
    p.comment_count
FROM
    {$wpdb->posts} p
WHERE
    p.post_password = ''
    AND p.post_type = '%s'
    AND p.post_status = 'publish'
    AND YEAR(p.post_date_gmt) = %d
    AND MONTH(p.post_date_gmt) = %d
    {$exPostSQL}
    {$exCatSQL}
ORDER BY
    p.post_date_gmt DESC

我想调整它,让它寻找p.post_status = 'publish' OR p.post_status = 't_active'

我试过了:

AND p.post_status = 'publish' OR p.post_status = 't_active'

但它没有用。你如何做到这一点?

这是一个入门级问题 - SQL 不是我的爵士乐。

标签: mysqlsql

解决方案


尝试使用AND (p.post_status = 'publish' OR p.post_status = 't_active')


推荐阅读