尝试在MySQL中执行减号操作 [英] Trying to perform MINUS operation in MySQL
问题描述
我试图在MySql中执行MINUS
操作.我有三个表:
I am trying to perform a MINUS
operation in MySql.I have three tables:
- 一个提供服务详细信息
- 一张表,其中说明要在其中提供服务
- 另一个表(基于邮政编码和状态)显示了不提供此服务的位置.
我能够分别获得这两个选择查询的输出.但是我需要一个合并的语句,将输出作为 "SELECT查询_1-SELECT查询_2".
I am able to get the output for those two select queries separately. But I need a combined statement that gives the output as 'SELECT query_1 - SELECT query_2'.
服务详细信息表 Service_Code(PK)服务名称
Service_Details Table Service_Code(PK) Service Name
服务状态表 Service_Code(FK)州国家PK(Service_Code,州,国家)
Servicing_States Table Service_Code(FK) State Country PK(Service_Code,State,Country)
例外表 Service_Code(FK)邮政编码状态PK(Service_Code,邮政编码,状态)
Exception Table Service_Code(FK) Zipcode State PK(Service_Code,Zipcode,State)
推荐答案
MySql无法识别 MINUS 和 INTERSECT ,这些都是基于Oracle的操作.在MySql中,用户可以将NOT IN
用作MINUS
(也有其他解决方案,但我非常喜欢它).
示例:
MySql does not recognise MINUS and INTERSECT, these are Oracle based operations. In MySql a user can use NOT IN
as MINUS
(other solutions are also there, but I liked it lot).
Example:
select a.id
from table1 as a
where <condition>
AND a.id NOT IN (select b.id
from table2 as b
where <condition>);
这篇关于尝试在MySQL中执行减号操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!