sábado, 1 de marzo de 2008

Obtener los códigos de los proyectos de los proveedores que venden todas las partes usadas en el proyecto “J1” y solo las partes usadas por el proyect

Siempre Trabajando sobre esta Base de Datos:
S(S#, Snombre, Situación, Ciudad)
P(P#, Pnombre, Color, Peso, Ciudad)
J(J#, Jnombre, ciudad)
SPJ(S#,P#,J#, Cantidad)

select S#
From S
Where not exists (Select P#
From P
Where exists (select *
From SPJ
Where P# = P.P# and J# = “J1”)
And not exists (select *
From SPJ
Where P# = P.P# and S# = S# = S.S#))
And not exists (Select P#
From P
Where exists (select *
From SPJ
Where P# = P.P# and S# = S.S#)
And not exists (select *
From SPJ
Where P# = P.P# and J# = “J1”));

Algebra: (SPJ where J#<> ‘j1’) [P#] P[P#] minus (SPJ where J# =’j1’) [P#]

No hay comentarios: