create table 仓库表
(仓库号 char(10),城市 char(10),面积 int)
insert into 仓库表 values('wh1','北京','370')
insert into 仓库表 values('wh2','上海','500')
insert into 仓库表 values('wh3','广州','200')
insert into 仓库表 values('wh4','武汉','400')
--update 仓库表
--set 仓库号='wh3' where 城市='广州'
--select * from 仓库表
create table 职工表(仓库号 char(10),职工号 char(10),工资 int)
insert into 职工表 values('wh2','e1','1220')
insert into 职工表 values('wh1','e3','1210')
insert into 职工表 values('wh2','e4','1250')
insert into 职工表 values('wh3','e6','1230')
insert into 职工表 values('wh1','e7','1250')
--select * from 职工表
create table 订货单表(职工号 char(10),供应商号 char(10),订购单号 char(10))
insert into 订货单表 values('e3','s7','or67')
insert into 订货单表 values('e1','s4','or73')
insert into 订货单表 values('e7','s4','or76')
insert into 订货单表 values('e6','','or77')
insert into 订货单表 values('e3','s4','or79')
insert into 订货单表 values('e1','','or80')
insert into 订货单表 values('e3','','or90')
insert into 订货单表 values('e3','s3','or91')
--select * from 订货单表
create table 供应商表 (供应商号 char(10),供应商名 char(40),地址 char(10))
insert into 供应商表 values('s3','振华电子厂','西安')
insert into 供应商表 values('s4','华通电子公司','北京')
insert into 供应商表 values('s6','607厂','郑州')
insert into 供应商表 values('s7','爱华电子厂','北京')检索哪些仓库中还没有职工的仓库的信息
检索哪些仓库中至少已经有一个职工的仓库的信息
检索有职工的工资大于或等于wh1仓库中任何一名职工工资的仓库号
检索有职工的工资大于或等于wh1仓库中所有职工工资的仓库号.

解决方案 »

  1.   

    都很简单,学习下就知道了!
    回答下第一个吧!
    不考虑效率,只实现
    select * from 仓库表 where 仓库号 not in (select 仓库号 from 职工表)
      

  2.   

    检索哪些仓库中至少已经有一个职工的仓库的信息select * from 仓库表 where 仓库号 in (select 仓库号 from 职工表) --这个就是了
    如果检索仓库中至少已经有N个职工的仓库的信息
    select a.仓库号,count(*) from 仓库表 a,职工表 b 
    where a.仓库号 =b.仓库号 
    group by a.仓库号
    having count(*)>=N
      

  3.   

    检索有职工的工资大于或等于wh1仓库中所有职工工资的仓库号.先找出wh1仓库工资最高的,只要大于这个工资就可以了
    select * from 职工表 
    where 仓库号<>'wh1' 
    and 工资>(select max(工资) from 职工表 where 仓库号='wh1') -----------------------
    你3和4的描述有区别吗?看你的问题,应该是考察sql中的some,any,all的用法
    记不清了,你自己查下吧!
      

  4.   

    参考一下吧:
    (1):select distinct ck.ckh,ck.city,ck.area from 仓库表 ck left join 职工表 zz on ck.ckh=zz.ckh where zz.zzh is null(2):select * from ck where ckh in
        ( select ckh from zz group by ckh having count(1)>=1)(3):select * from zz where gz>=any(select gz from zz where ckh='wh1')(4):select * from zz where gz>=all(select gz from zz where ckh='wh1')
      

  5.   

    --1  检索哪些仓库中还没有职工的仓库的信息 
    select 仓库号
      from f_仓库表
     where 仓库号 not in (select 仓库号
                         from (select a.仓库号, a.城市, a.面积 --,b.职工号
                                 from f_仓库表 a, f_职工表 b
                                where a.仓库号 = b.仓库号))--2  检索哪些仓库中至少已经有一个职工的仓库的信息 
    select 仓库号,城市,面积,职工号,工资
      from (select a.仓库号, a.城市, a.面积,b.职工号,b.工资
              from f_仓库表 a, f_职工表 b
             where a.仓库号 = b.仓库号)
    --3  检索有职工的工资大于或等于wh1仓库中任何一名职工工资的仓库号 
    select 仓库号, 工资
      from (select a.仓库号, a.城市, a.面积, b.职工号, b.工资
              from f_仓库表 a, f_职工表 b
             where a.仓库号 = b.仓库号
               and a.仓库号 <> 'wh1') c
     where c.工资 >
           (select 工资
              from (select 仓库号, min(工资) as 工资
                      from (select a.仓库号, a.城市, a.面积, b.职工号, b.工资
                              from f_仓库表 a, f_职工表 b
                             where a.仓库号 = b.仓库号)
                     where 仓库号 = 'wh1'
                     group by 仓库号))
    --4  检索有职工的工资大于或等于wh1仓库中所有职工工资的仓库号.
    select 仓库号, 工资
      from (select a.仓库号, a.城市, a.面积, b.职工号, b.工资
              from f_仓库表 a, f_职工表 b
             where a.仓库号 = b.仓库号
               and a.仓库号 <> 'wh1') c
     where c.工资 >=
           (select 工资
              from (select 仓库号, max(工资) as 工资
                      from (select a.仓库号, a.城市, a.面积, b.职工号, b.工资
                              from f_仓库表 a, f_职工表 b
                             where a.仓库号 = b.仓库号)
                     where 仓库号 = 'wh1'
                     group by 仓库号))