mysql - 我需要在此 SQL 指令中添加什么来过滤某些项目?

标签 mysql sql

我想要的是过滤(而不是获取)出现在这个新表中的报价,我们将其用作黑名单(即,对于域 X,我们不希望来源为 Y 的报价)。

TABLE:      black_list_deals

COLUMNS: id 
         domain_id (we save here an id from the table "domain")
         origin_offer (we save here a value from deal, the field deal_source_id)

直到现在我一直在使用这个指令,但现在我需要添加新的行为来根据黑名单表过滤这些商品。

SELECT
    a.lat,
    a.lon,
    a.id,
    a.image,
    a.link,
    a.deal_source_id,
    a.date_posted,
    a.date_expires,
    a.tags_external,
    a.tags_internal,
    a.gender,
    a.price,
    a.discount,
    a.areas,
    a.hits,
    a.bias,
    a.collection_type,
    a.uniqueness,
    a.date_posted = current_date AS today,
    DATEDIFF( a.date_expires, current_date) AS days_remaining,
    a.collection_type,
    b.id AS area_id,
    b.area,
    a.image_thumb,
    c.source_img_email,
    c.source_price,
    c.source_img_sm,
    c.source_name,
    c.frame,
    a.date_posted = current_date AS today,
    d.country,
    d.region,
    e.level1,
    e.level2,
    e.level3,
    e.level4

FROM deal a
      LEFT JOIN area b ON (a.areas = b.id)
      LEFT JOIN deal_source c ON (a.deal_source_id = c.id)
      LEFT JOIN deal_travel d ON (a.id = d.deal_id)
      LEFT JOIN deal_travel_country e ON (d.country = e.id)
WHERE
      a.validated = 'y' AND
      a.date_posted = current_date AND
      a.date_expires >= current_date AND
      email_deal = '1'

最佳答案

WHERE a.deal_source_id NOT IN (SELECT origin_offer FROM black_list_deals) 添加到您的 WHERE 子句应该可以解决这个问题。

关于mysql - 我需要在此 SQL 指令中添加什么来过滤某些项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14329757/

相关文章:

sql - 您查询什么表/ View 以选择 Oracle 模式中的所有表名?

带有 COUNT(*) 问题的 SQL LEFT JOIN

php - MySQL:查询另一个查询结果并返回两个结果?

javascript - sequelize 将日期与日期时间戳进行比较

php - 访问部分子查询以在 PHP 服务器中构建 HTML

php - 整个文本不会显示在表格中,PHP

sql - Oracle中如何选择表中最后插入的记录

mysql - 使用 Wt::Dbo 导致 MySQL 准备语句泄漏

php - 如何将表单的复选框名称存储到 php 数组

mysql - "if"查询mysql