10-81 spj-显示每个工程项目使用零件的供应列表

题目要求编写SQL语句,在SPJ数据库中,显示每个工程项目所使用的提供零件数量少于100的供应列表,如工程项目尚未有供应商提供零件的也要列出。输出结果集以工程项目jno升序排序。

select a.jno,jname,sname,pname,qty
from (
  select spj.jno,jname
  from j,spj
  where j.jno=spj.jno and qty<100
) a inner join (
  select spj.jno,sname
  from s,spj
  where s.sno=spj.sno and qty<100
) b on b.jno=a.jno
inner join (
  select spj.jno,pname,qty
  from p,spj
  where p.pno=spj.pno and qty<100
) c on c.jno=a.jno
union
select jno,jname,NULL as sname,NULL as pname,0 as qty
from j
where jno not in (
  select distinct jno
  from spj
)
order by jno asc;

注:请注重其中的方法希望能帮助到大家

你可能感兴趣的:(sql,数据库)