mysql 减号_尝试在MySQL中执行减号操作

bd96500e110b49cbb3cd949968f18be7.png

I am trying to perform a MINUS operation in MySql.I have three tables:

one with service details

one table with states that a service is offered in

another table (based on zipcode and state) shows where this service is not offered.

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_Details Table

Service_Code(PK) Service Name

Servicing_States Table

Service_Code(FK) State Country PK(Service_Code,State,Country)

Exception Table

Service_Code(FK) Zipcode State PK(Service_Code,Zipcode,State)

解决方案

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

AND a.id NOT IN (select b.id

from table2 as b

where );

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值