设计一个数据库的关系模式如下:
S(S#, SNAME, CITY)
P(P#, PNAME, COLOR, WEIGHT)
J(J#, JNAME, CITY)
SPJ(S#, P#, J#, QTY)
其中,
S为供应商关系,S#表示供应商号,SNAME表示供应商名称,CITY表示供应商所在城市;
P为零件关系,P#表示零件编号,PNAME表示零件名称,COLOR表示零件颜色,WEIGHT表示零件重量;
J为工程关系,J#表示工程号,JNAME表示工程名,CITY表示工程所在城市;
SPJ为供应关系,S#、P#、J#的含义同前,QTY表示供应的零件数1. 查询所有工程的编号、名称和所在城市
2. 查询重量不大于50的零件编号和名称
3. 查询提供零件名为“P1”的供应商号和所在城市
4. 查询供应商与工程所在城市相同的供应商提供的零件编号和零件名
5. 查询没有使用颜色为RED或BLUE的零件的工程的全部情况

解决方案 »

  1.   

    1. 查询所有工程的编号、名称和所在城市 
    这个还要问呀select *
    from J
      

  2.   

    1. 查询所有工程的编号、名称和所在城市 
    select * from J2. 查询重量不大于50的零件编号和名称 
    select P.P# , P.PNAME from P where WEIGHT <= 503. 查询提供零件名为“P1”的供应商号和所在城市 
    select S.S# , S.CITY from S , SPJ , P where S.S# = SPJ.S# and SPJ.P# = P.P# and P.PNAME = 'P1'4. 查询供应商与工程所在城市相同的供应商提供的零件编号和零件名 
    select S.P#, S.PNAME from S , J where S.CITY = J.CITY5. 查询没有使用颜色为RED或BLUE的零件的工程的全部情况 
    select J.* from J where J# not in (select SPJ.J# from SPJ where J# in (select distinct P.P# from P where COLOR = 'RED' or COLOR = 'BLUE'))
      

  3.   

    我到觉得提出的很基础,出的很好,如果对于刚刚毕业的人来说,还可以,层次可以看出来的,老乌龟的精神我们应该学习!1  
    select * from J2
    select P# , PNAME from P where WEIGHT <= 53.  
    select S.S# , S.CITY from S , SPJ , P where S.S# = SPJ.S# and SPJ.P# = P.P# and P.PNAME = 'P1'4.  
    select S.P#, S.PNAME from S , J where S.CITY = J.CITY 

    select J.* from J where J# not in (select SPJ.J# from SPJ where J# in (select distinct P.P# from P where COLOR IN( 'RED','BLUE')
      

  4.   


    --1. 查询所有工程的编号、名称和所在城市
    select * from J --2. 查询重量不大于50的零件编号和名称 
    select P#,Pname from P where weight<50--3. 查询提供零件名为“P1”的供应商号和所在城市 
    select s.S#,city from S,P,spj a where s.S#=a.S# and a.P#=p.P# and pname='P1'--4. 查询供应商与工程所在城市相同的供应商提供的零件编号和零件名 
    select p.P#,Pname from p,s,spj a,j where s.S#=a.S# and a.P#=p.P#
    and a.J#=j.J# and p.city=j.city--5. 查询没有使用颜色为RED或BLUE的零件的工程的全部情况 
    select j.* from J,p,spj a where j.j#=a.j# and p.p#=a.p#
    and p.color not in('red','blue')