【问题标题】:Mysql with multiple query having NAND opertaion and NOT operation具有 NAND 操作和 NOT 操作的多个查询的 Mysql
【发布时间】:2013-06-01 02:10:19
【问题描述】:

我正在尝试在查询之间实现与 NOT 操作和 NAND 操作。

场景一:

 SELECT 
    country_name,country_code 
       from country 
       where not (country_name='Land islands' and country_code='AX');

效果很好;显示除我提到的两个国家/地区以外的所有其他国家/地区。

场景 2:

当我尝试在 where 条件中进行一些选择时,它会显示错误。

 SELECT * from
   country 
     where not 
       (SELECT * from country 
              where country_name='Land islands' 
        and 
        SELECT * from country
               where country_code='AX');

显示错误..

Kindly refer the Link:我之前的问题以及NOT和NAND操作的工作原理。

MySQL NAND/NOR operations in Queries

【问题讨论】:

    标签: mysql database operators logic


    【解决方案1】:

    AND 应替换为UNION,表的primary key(假设为id)应使用NOT IN 子句进行检查。

    SELECT * from country 
    WHERE id NOT IN
           (SELECT id from country 
                  where country_name='Land islands' 
            UNION
            SELECT id from country
                   where country_code='AX'
            );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-25
      • 1970-01-01
      • 2020-08-24
      • 2011-01-22
      相关资源
      最近更新 更多