mysql - 在 MySQL 中,如何将 Intersection 用法应用于 3 个以上的选择语句?

标签 mysql

我有 9 个精选句子。我想得到 9 个选择结果的交集。 但我将 intersect 应用于我的代码,但它不起作用。

下面是我的代码。

 (SELECT code_co.code, code_co.disease_co, code_en.disease_en
 FROM code_co
 LEFT JOIN code_en ON code_en.code = code_co.code
 LEFT JOIN note ON note.code = code_co.code
 LEFT JOIN inclusion ON inclusion.code = code_co.code
 LEFT JOIN exclusion ON exclusion.code = code_co.code
 LEFT JOIN ds ON code_co.code = ds.code
 LEFT JOIN tx ON code_co.code = tx.code
 LEFT JOIN sx ON code_co.code = sx.code
 CROSS JOIN (
     SELECT CONCAT(  '%', ds_word.ds_en,  '%' ) AS pattern
     FROM ds_word
     WHERE ds_co LIKE  '%".$search[0]."%'
     LIMIT 0 , 1
     )const
 WHERE note LIKE const.pattern
 OR ds_content LIKE const.pattern
 OR disease_en LIKE const.pattern 
 OR sx_content LIKE const.pattern
 OR tx_content LIKE const.pattern
 OR exclusion LIKE const.pattern
 OR inclusion LIKE const.pattern
 )
 intersect

 (SELECT code_co.code, code_co.disease_co, code_en.disease_en
 FROM code_co
 LEFT JOIN code_en ON code_en.code = code_co.code
 LEFT JOIN note ON note.code = code_co.code
 LEFT JOIN inclusion ON inclusion.code = code_co.code
 LEFT JOIN exclusion ON exclusion.code = code_co.code
 LEFT JOIN ds ON code_co.code = ds.code
 LEFT JOIN tx ON code_co.code = tx.code
 LEFT JOIN sx ON code_co.code = sx.code
 CROSS JOIN (
 SELECT CONCAT(  '%', ds_word.ds_en,  '%' ) AS pattern
      FROM ds_word
      WHERE ds_co LIKE  '%".$search[1]."%'
      ....
 OR inclusion LIKE const.pattern
 )

intersect

(SELECT code_co.code, code_co.disease_co, code_en.disease_en
 FROM code_co
 LEFT JOIN code_en ON code_en.code = code_co.code
 ... /* for search[2] */
 OR inclusion LIKE const.pattern
 )

但是相交不起作用。 请帮助我进行相交使用。

最佳答案

MySQL没有相交指令,你可以在这里查看如何模拟:

Alternative to Intersect in MySQL

我假设您正在使用MySQL,这是问题标签的原因

关于mysql - 在 MySQL 中,如何将 Intersection 用法应用于 3 个以上的选择语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21884771/

相关文章:

每个客户交易输出 "Prior Transaction Date"的 MYSQL 查询

MySql 查询以加入表之间不同存储的 uuid

SQL WHEREing 在不同表的 COUNT

mysql - Linux Antergos 安装 MySql

c# - 如何在不使用 c# 中的 for 或 foreach 循环的情况下使用数据表从特定的 mysql 表中获取每个值?

php - Laravel 5.8 Eloquent 无法按预期工作,尽管它的原始转储查询有效

mysql - 字段列表中临时表的未知列

mysql - 如何将SQL请求中的文本替换成ASCII字符的组合?

MySQL - 计算具有唯一文本的唯一值的数量

php - 数据库设计: join with uid or with two fields