【发布时间】:2016-01-12 00:30:04
【问题描述】:
我有这个问题
select lab.IDLAB,
lab.NOMLAB,
lab.CAPACIDAD
from laboratorio lab
inner join DETALLESOLICITUD det on det.IDLAB = lab.IDLAB
inner join dia on dia.iddia = det.iddia
inner join bloque blo on blo.idbloque = det.idbloque
inner join solicitud sol on sol.IDSOLICITUD=det.IDSOLICITUD
where blo.idbloque = 1
and dia.iddia = 1
and sol.estado in (1,2)
返回:
IDLAB | NOMLAB | CAPACIDAD
----------------------------
1 | LCOMP1 | 22
它完全符合我的要求。现在我想从表laboratorios 中获取所有没有出现在这个查询中的记录。例如我的laboratorios 表有内容:
IDLAB | NOMLAB | CAPACIDAD
----------------------------
1 | LCOMP1 | 22
2 | LCOMP2 | 31
3 | LCOMP3 | 17
4 | LCOMP4 | 26
我想要以下输出:
IDLAB | NOMLAB | CAPACIDAD
----------------------------
2 | LCOMP2 | 31
3 | LCOMP3 | 17
4 | LCOMP4 | 26
我用这种方式尝试了not exists 声明:
select *
from laboratorio
where not exists(
select lab.idlab, lab.nomlab, lab.CAPACIDAD
from laboratorio lab
inner join DETALLESOLICITUD det on det.idlab = lab.idlab
inner join dia on dia.iddia = det.iddia
inner join bloque blo on blo.idbloque = det.idbloque
inner join solicitud sol on sol.IDSOLICITUD = det.IDSOLICITUD
where blo.idbloque = 1
and dia.iddia = 1
and sol.estado in(1,2)
);
这样:
select *
from laboratorio
where not exists(
select det.IDLAB
from DETALLESOLICITUD det
inner join dia on dia.iddia = det.iddia
inner join bloque blo on blo.idbloque = det.idbloque
inner join solicitud sol on sol.IDSOLICITUD = det.IDSOLICITUD
where blo.idbloque = 1
and dia.iddia = 1
and sol.estado in(1,2)
);
但两者都没有返回任何内容。任何帮助将不胜感激。
【问题讨论】:
-
请发布一些数据,您需要的输出将对我们有所帮助!!
-
我制作的版本@Tarun
-
感谢您删除我的编辑,这使您的问题更具可读性。
-
对不起@APC,有人问我预期的输出,然后我看到我的版本被删除了,所以我回滚了。可能我应该让代码部分更具可读性
标签: sql oracle subquery not-exists