如何解决这个sql查询?

发布于 2024-11-17 06:10:29 字数 569 浏览 0 评论 0原文

我有以下查询来从 wpr_subscribers 获取行,前提是查询中的条件。

SELECT subscribers.* FROM wpr_subscribers subscribers, wpr_followup_subscriptions subscriptions WHERE 
            subscribers.id=subscriptions.sid AND
            subscribers.active=1 AND
            subscribers.confirmed=1 AND
            subscriptions.type='autoresponder' AND
            subscriptions.eid=$autoresponder_id AND 
            subscriptions.sequence = -2 OR
            CEIL((subscriptions.last_date-subscriptions.doc)/86400) >= $message_index

该查询返回每行中的两个。我该如何解决这个问题?

I have the following query to fetch rows from wpr_subscribers provided that the conditions in the query.

SELECT subscribers.* FROM wpr_subscribers subscribers, wpr_followup_subscriptions subscriptions WHERE 
            subscribers.id=subscriptions.sid AND
            subscribers.active=1 AND
            subscribers.confirmed=1 AND
            subscriptions.type='autoresponder' AND
            subscriptions.eid=$autoresponder_id AND 
            subscriptions.sequence = -2 OR
            CEIL((subscriptions.last_date-subscriptions.doc)/86400) >= $message_index

The query returns two of every row. How do I solve this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心碎无痕… 2024-11-24 06:10:29
SELECT DISTINCT subscribers.* FROM wpr_subscribers subscribers, wpr_followup_subscriptions
subscriptions WHERE 
        subscribers.id=subscriptions.sid AND
        subscribers.active=1 AND
        subscribers.confirmed=1 AND
        subscriptions.type='autoresponder' AND
        subscriptions.eid=$autoresponder_id AND 
        subscriptions.sequence = -2 OR
        CEIL((subscriptions.last_date-subscriptions.doc)/86400) >= $message_index

DISTINCT 关键字将帮助您仅返回表中唯一(不同)的行。您确定查询中 AND 和 OR 的逻辑以及您现在收到的唯一数据确实正确吗?仅供参考,AND 运算符优先于 OR,但您可以使用括号覆盖它。

SELECT DISTINCT subscribers.* FROM wpr_subscribers subscribers, wpr_followup_subscriptions
subscriptions WHERE 
        subscribers.id=subscriptions.sid AND
        subscribers.active=1 AND
        subscribers.confirmed=1 AND
        subscriptions.type='autoresponder' AND
        subscriptions.eid=$autoresponder_id AND 
        subscriptions.sequence = -2 OR
        CEIL((subscriptions.last_date-subscriptions.doc)/86400) >= $message_index

DISTINCT keyword would help you in returning only the unique(distinct) rows in the table. Are you sure on the logic of AND and OR in the query and the unique data that you will now receive is indeed correct. Just for the info, AND operator has precedence over OR however you can override that by using parenthesis.

痴意少年 2024-11-24 06:10:29

它可能是您的 OR 语句,

        subscriptions.sequence = -2 OR
        CEIL((subscriptions.last_date-subscriptions.doc)/86400) >= $message_index

无论 OR 的范围是什么,您都应该将其括在括号中

It is probably your OR statement

        subscriptions.sequence = -2 OR
        CEIL((subscriptions.last_date-subscriptions.doc)/86400) >= $message_index

You should enclose this in parenthesis for whatever the scope of the OR is

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文