仓库练习

create database 仓库
create table 仓库表
(
 仓库号 varchar(50)primary key not null,
 城市  varchar(50) not null,
 面积  int not null,
)
truncate table 仓库表
insert into 仓库表 values ('wh1','北京',370)
insert into 仓库表 values ('wh2','上海',500)
insert into 仓库表 values ('wh3','广州',200)
insert into 仓库表 values ('wh4','武汉',400)
create table 职工表
(
 仓库号 varchar(50) not null,
 foreign key (仓库号)
 references 仓库表(仓库号),
 职工号 varchar(50) primary key not null,
 工资 int  not null
)
truncate table 职工表
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)
create table 订购单表
(
  职工号  varchar(50) not null,
  foreign key (职工号)
 references 职工表 (职工号),
  供应商号   varchar(50) ,
  foreign key (供应商号 )
 references 供应商表(供应商号 ),
  订购单号 varchar(50) not null,
  订购日期 date 
)
truncate table 订购单表
insert into 订购单表 values ('e3','s7','or67','2001-6-23')
insert into 订购单表 values ('e1','s4','or73','2001-7-28')
insert into 订购单表 values ('e7','s4','or76','2001-5-25')
insert into 订购单表 values ('e6',null,'or77',null)
insert into 订购单表 values ('e3','s4','or79','2001-6-13')
insert into 订购单表 values ('e1',null,'or80',null)
insert into 订购单表 values ('e3',null,'or90',null)
insert into 订购单表 values ('e3','s3','or91','2001-7-13')
create table 供应商表
(
 供应商号   varchar(50)primary key not null ,
 供应商名  varchar(50) not null,
 地址 varchar(50) not null,
)
truncate table 供应商表
insert into 供应商表 values ('s3','振华电子厂','西安')
insert into 供应商表 values ('s4','华通电子公司','北京')
insert into 供应商表 values ('s6','607厂','郑州')
insert into 供应商表 values ('s7','爱华电子厂','北京')
select*from 仓库表

select*from 职工表
select*from 订购单表
select*from 供应商表
--1.从职工关系中检索所有工资值。
select 工资 from 职工表
--2.检索仓库关系中的所有记录。
select*from 仓库表
--3.检索工资多于1230元的职工号。
select 职工号 from  职工表 where 工资>1230
--4.检索哪些仓库有工资多于1210元的职工。
select 职工号,仓库号 from  职工表 where 工资>1210
--5.给出在仓库“wh1”或“wh2”工作,并且工资少于1250元的职工号。
select 职工号 from  职工表 where 仓库号 like 'wh3' and 工资<1250
--6.找出工资多于1230元的职工号和他们所在的城市。 
select 城市 ,职工号 from 仓库表 join  职工表 on 职工表.仓库号=仓库表.仓库号 where 工资>1230 
--7.找出工作在面积大于400的仓库的职工号以及这些职工工作所在的城市。
select 城市 ,职工号 from 仓库表 join  职工表 on 职工表.仓库号=仓库表.仓库号 where 工资>1230 and 面积>400
--8 .哪些城市至少有一个仓库的职工工资为1250元。
select 城市 from 仓库表 where 仓库号 in (select 仓库号 from 职工表 where 工资='1250')     
--9.......查询所有职工的工资都多于1210元的仓库的信息。
select *from 仓库表 where 仓库号 in( select  仓库号 from 职工表 where 1210< all(select 工资 from 职工表  where 仓库表.仓库号=职工表 .仓库号 ))
--10.找出和职工e4挣同样工资的所有职工。
select *from 职工表 where 工资 =( select  工资 from 职工表 where 工资=1250 and 职工号 ='e4')and 职工号 !='e4'
--11.检索出工资在1220元到1240元范围内的职工信息。
select*from 仓库表 join  职工表 on 职工表.仓库号=仓库表.仓库号 where 工资  between 1220 and 1240
--12.从供应商关系中检索出全部公司的信息,不要工厂或其他供应商的信息。
select*from 订购单表
--13.找出不在北京的全部供应商信息。
select*from 供应商表 where 地址 !='北京'
--14.按职工的工资值升序检索出全部职工信息。
select*from 仓库表 join  职工表 on 职工表.仓库号=仓库表.仓库号 order by 工资
--15.先按仓库号排序,再按工资排序并输出全部职工信息。
select *from 职工表 order by 仓库号,工资
--16.找出供应商所在地的数目。
select 地址,COUNT(*) from 供应商表 group by 地址 
--17.求支付的工资总数。
select sum(工资) from  职工表
--18.求北京和上海的仓库职工的工资总和。
select sum(工资) from  职工表 join 仓库表 on 职工表.仓库号=仓库表.仓库号 where 城市 IN('北京','上海')
--19.求所有职工的工资都多于1210元的仓库的平均面积。
select AVG(面积) from 仓库表 where 仓库号 in(select 仓库号 from 职工表 where 工资>=1210 )
--20.求在wh2仓库工作的职工的最高工资值。
select max(工资) from  职工表 where 仓库号='wh2'
--21.求每个仓库的职工的平均工资。
select 仓库号,avg(工资) from 职工表 group by 仓库号
--22.求至少有两个职工的每个仓库的平均工资。
select 仓库号,avg(工资) from 职工表 group by 仓库号 having COUNT(*)>1
--23.找出尚未确定供应商的订购单。
select* from 订购单表 where 供应商号 is null
--24.列出已经确定了供应商的订购单信息。
select* from 订购单表 join 供应商表 on 供应商表.供应商号=订购单表.供应商号 where 订购单表.供应商号 is not null
--25.查询供应商名。
select 供应商名 from 供应商表
--26.在订购单表中加入一个新字段总金额,说明完成该订购单所应付出的总金额数。
alter table 订购单表 add sum_money varchar(max);
--27.列出每个职工经手的具有最高总金额的订购单信息。
select  职工号, MAX(sum_money) from 订购单表 group by 职工号
--28.检索哪些仓库中还没有职工的仓库的信息。
select * from 仓库表 where 仓库号 not in (select 仓库号 from 职工表) 
--29.检索哪些仓库中至少已经有一个职工的仓库的信息。
select * from 仓库表 where 仓库号 in(select 仓库号 from 职工表) 
--30.检索有职工的工资大于或等于wh1仓库中任何一名职工工资的仓库号。
select 仓库号 from 职工表 where 工资>= all(select 工资 from 职工表 where 仓库号='wh1') and 仓库号!='wh1' 
--31.检索有职工的工资大于或等于wh1仓库中所有职工工资的仓库号。
select 仓库号 from 职工表 where 工资>=any(select 工资 from 职工表 where 仓库号='wh1') and 仓库号!='wh1' 

 

转载于:https://www.cnblogs.com/Mr-xue/p/4451885.html

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值