数据库的操作:订货管理练习

以下是一个订货管理数据库,包含有仓库表、职工表、订购单表、供货商表:

在这里插入图片描述
在这里插入图片描述
首先,建表:
1.仓库表=Table_wh
仓库号=whnum,城市=city,面积=area;
2.职工表=Table_wr
仓库号=whnum,职工号=wrnum,工资=salary;
3.订购单表=Table_or
职工号=wrnum,供应商号=Suppliernum,订购单号=ordername,订单金额=oedermuch,订购日期=datetime;
4.供应商表=Table_sr
供应商号=Suppliernum,供应商名=Suppliername,地址=address。

(1)查询工资多于1230元的职工号和他们所在的城市。
select wrnum,city from Table_wr,Table_wh
where Table_wr.whnum  = Table_wh.whnum and salary>1230;

(2)查询工作在面积大于400的仓库的职工号以及这些职工工作所在的城市。
select wrnum,city from Table_wr,Table_wh 
where Table_wr.whnum  = Table_wh.whnum and area>400;

(3)查询和职工e4挣同样工资的所有职工信息。
select * from Table_wr 
where salary = (select salary from Table_wr where wrnum = 'e4')and wrnum != 'e4';

(4)先按仓库号排序,再按工资降序排序并输出全部职工信息。
select * from Table_wr order by salary DESC;
select * from Table_wr order by whnum;

(5)求北京和上海的仓库职工的工资总和。
select SUM(salary) from Table_wr
where whnum in (select whnum from Table_wh where city in ('北京','上海'))

(6)求至少有两个职工的每个仓库的平均工资。
select whnum,AVG(salary) from Table_wr 
group by whnum having COUNT(whnum)>1

(7)列出每个职工经手的具有最高总金额的订购单信息。
select * from Table_or 
where ordermuch in (
select MAX(ordermuch) from Table_or  
group by wrnum)

(8)查询仓库中还没有职工的仓库信息。
select * from Table_wh 
where whnum not in (select whnum from Table_wr )

(9)查询有职工的工资大于或等于wh1仓库中任何一名职工工资的仓库号。
select whnum from Table_wr 
where salary >=any (
select salary from Table_wr 
where whnum='wh1')
and whnum!='wh1' group by whnum

(10)查询有职工的工资大于或等于wh1仓库中所有职工工资的仓库号。
select whnum from Table_wr 
where salary >=all (
select salary from Table_wr 
where whnum='wh1')
and whnum!='wh1' group by whnum
写在后面:

宁静的夜晚。你也思念我也思念。轻数珍藏的记忆,校园月影留恋。恣意的夜风触摸温馨,多情的蟋蟀陶醉爱海里呢喃。河水涟漪倾述,含羞月光偷窥相拥的青年。流年的素笺把时光临慕,千回百转轻拾岁月点点。韶光安然溢上心田。为梦看淡月缺月圆。

猜你喜欢

转载自blog.csdn.net/weixin_43912621/article/details/105352383