显示两个表均不可用的应用程序计数或报告

时间:2019-06-18 08:20:11

标签: sql oracle

显示两个表都不可用的应用程序计数或报告 (服务,服务完成)

注意: 服务= Application_no(编号) Services_Done = Application_no( Varchar2

SELECT Count(Application_no)
FROM services
WHERE Application_cat = 60
and To_char(Delivery_date,'yyyy') between 2006 and 2016
and Service_status = 210

SELECT services.application_no
FROM services
WHERE Application_status = 15
and To_char(Directors_Dependency_Date,'yyyy') between 2006 and 2016
MINUS
SELECT services.application_no
FROM services
JOIN services_contract ON services.application_no=services_contract.application_no

结果:

如果应用程序在服务中可用,但在services_done中不可用-包括它 如果两个表中的Application_no =排除它

2 个答案:

答案 0 :(得分:1)

如果我理解正确,则可以使用NOT EXISTS子句。查看下面的示例

SELECT Count(Application_no) FROM services s
WHERE Application_cat = 60
and To_char(Delivery_date,'yyyy') between 2006 and 2016
and Service_status = 210
and not exists
(
   select 1 from services_done t2 where t2.cond = s.cond
)

答案 1 :(得分:0)

如果ApplicationServicesServices_Done中具有相同的ID,则可以像这样进行LEFT JOIN

SELECT Count(S.App)
FROM Services as S
LEFT JOIN Services_Done as SD
ON S.App = SD.App
WHERE SD.App is not null;

如果满足条件WHERE,则意味着为对象Services找到了Services_DoneApplication之间的链接。