--仓库表:
--仓库号    城市    面积
--wh1    北京    370
--wh2    上海    500
--wh3    广州    200
--wh4    武汉    400
create table cangku
(
cno varchar(50) primary key not null,--将仓库号设为主键
city varchar(50) not null,
mianji int not null)
go
insert into cangku values('wh1','北京',370);
insert into cangku values('wh2','上海',500);
insert into cangku values('wh3','广州',200);
insert into cangku values('wh4','武汉',400);
select *from cangku
--职工表:
--仓库号    职工号    工资
--wh2    e1    1220
--wh1    e3    1210
--wh2    e4    1250
--wh3    e6    1230
--wh1    e7    1250
create table zhigong
(
cno varchar(50) references cangku(cno),--仓库号为外键
zhigonghao varchar(50) primary key not null,--职工号设为主键
gongzi int not null
)
insert into zhigong values('wh2','e1',1220);
insert into zhigong values('wh1','e3',1210);
insert into zhigong values('wh2','e4',1250);
insert into zhigong values('wh3','e6',1230);
insert into zhigong values('wh1','e7',1250);
select *from zhigong--订购单表:
--职工号    供应商号    订购单号    订购日期
--e3    s7    or67    2001-6-23
--e1    s4    or73    2001-7-28
--e7    s4    or76    2001-5-25
--e6    null    or77      -   -
--e3    s4    or79    2001-6-13
--e1    null    or80      -   -
--e3    null    or90      -   -
--e3    s3    or91    2001-7-13
create table dinggou--订购单表
(zhigonghao varchar(50) references zhigong(zhigonghao),--职工号设为外键gongyingshanghao varchar(50) references gongyingshang(gongyingshanghao) ,goudanhao varchar(50) not null,goudanri varchar(50),
)
insert into dinggou values('e3','s7','or67','2017-6-23')
insert into dinggou values('e1','s4','or73','2017-7-28')
insert into dinggou values('e7','s4','or76','2017-5-25')
insert into dinggou values('e6',null,'or77','--')
insert into dinggou values('e3','s4','or79','2017-6-13')
insert into dinggou values('e1',null,'or80','--')
insert into dinggou values('e3',null,'or90','--')
insert into dinggou values('e3','s3','or91','2017-7-13')
select *from dinggou
drop table dinggou
--供应商表:
--供应商号    供应商名    地址
--s3    振华电子厂    西安
--s4    华通电子公司    北京
--s6    607厂    郑州
--s7    爱华电子厂    北京
create table gongyingshang--供应商表
(
gongyingshanghao varchar(50) primary key,
gongyingshangming varchar(50) not null,
dizhi varchar(50) not null,
)
insert into gongyingshang values('s3','振华电子厂','西安')
insert into gongyingshang values('s4','华通电子公司','北京')
insert into gongyingshang values('s6','607厂','郑州')
insert into gongyingshang values('s7','爱华电子厂','北京')
select *from gongyingshang
--1,从职工关系中检索所有工资值.
select *from zhigong
select gongzi from zhigong
--2,检索仓库关系中的所有记录,
select *from cangku
--3,检索工资多于1230元的职工号.
select *from zhigong
select zhigonghao from zhigong where gongzi>1230
--4.检索哪些仓库有工资多于1210元的职工select cno from zhigong where gongzi>1230
--5,给出在仓库“wh1”或“wh2”工作,并且工资少于1250元的职工号
select *from zhigong
select zhigonghao from zhigong where cno in ('wh1','wh2')and gongzi<1250
--找到了职工号来自于职工表 从仓库里找寻wh1或者wh2,并且工资高于1250
--6,找出工资多于1230元的职工号和他们所在的城市。
select *from cangku
select *from zhigong
select city,zhigonghao from zhigong
join cangku on cangku.cno=zhigong.cno and gongzi>1230
--7,找出工作在面积大于400的仓库的职工号以及这些职工工作所在的城市。
select *from cangkuselect cno,city from cangku where mianji>400
--8,.哪些城市至少有一个仓库的职工工资为1250元。
select *from cangku
select *from zhigong
--select city from  cangku where cno in(select cno from zhigong where gongzi=1250)
select city from  cangku where cno in(select cno from zhigong where gongzi=1250 group by cno having COUNT(*)>=1)
--9.查询所有职工的工资都多于1210元的仓库的信息
select *from zhigong
select *from cangku where cno in(select cno from zhigong group by cno having MIN(gongzi)>1210)
--10.找出和职工e4挣同样工资的所有职工。
select gongzi from zhigong where zhigonghao='e4'
select zhigonghao from zhigong where gongzi in (select gongzi from zhigong where zhigonghao='e4')--11.检索出工资在1220元到1240元范围内的职工信息select *from zhigong where gongzi between 1220 and 1240
--12.从供应商关系中检索出全部公司的信息,不要工厂或其他供应商的信息
select *from gongyingshang
select *from cangku
select *from gongyingshang where gongyingshangming like('%公司')
--13.找出不在北京的全部供应商信息。
select *from gongyingshang where dizhi!='北京'
--14.按职工的工资值升序检索出全部职工信息。
select *from zhigong order by gongzi --order by 排序 默认从小到大
--15.先按仓库号排序,再按工资排序并输出全部职工信息。
select *from zhigong order by cno,gongzi
--16.找出供应商所在地的数目。
select *from gongyingshang
select count(*),dizhi from gongyingshang group by dizhi
--17.求支付的工资总数
select *from zhigong
select sum(gongzi)as 工资总和 from zhigong
--18.求北京和上海的仓库职工的工资总和
select *from zhigong
select *from cangku
select cno from cangku where city in('北京','上海')
select sum(gongzi) 工资总和 from zhigong where cno in (select cno from cangku where city in('北京','上海'))--19.求所有职工的工资都多于1210元的仓库的平均面积
select *from zhigong
select *from cangkuselect avg(mianji) as 平均面积 from cangku  where cno in(select cno from zhigong group by cno having MIN(gongzi)>1210)
--20.求在wh2仓库工作的职工的最高工资值
select *from zhigong
select *from zhigong where cno='wh2'
select  MAX(gongzi)as 最高工资值 from zhigong where cno='wh2'

--

转载于:https://www.cnblogs.com/w-wz/p/4456959.html

4.25 数据库 仓库例题相关推荐

  1. Azure SQL 数据库仓库Data Warehouse (3) DWU

    <Windows Azure Platform 系列文章目录> 在笔者的上一篇文章中:Azure SQL 数据库仓库Data Warehouse (2) 架构 介绍了SQL DW的工作节点 ...

  2. [课业] 25 | 数据库基础 | 基础SQL查询语言

    文章目录 知识 介绍 创建数据库 简单选择语句 子查询 概述 IN谓词 量化比较谓词 EXISTS谓词 BETWEEN谓词 IS NULL谓词 LIKE谓词 UNION操作符和FOR ALL条件 一些 ...

  3. Oracle数据库面试例题

    标题:在oracle数据库中,对货拉拉笔试题目进行解析 今天给大家讲解一个货拉拉的面试题目,这是一个和case when 有关系的典型的例题,可以帮助我们理解遇到这一种大类的问题时如何去处理和比例计算 ...

  4. spss连接mysql_通过结合使用 SPSS 与数据库仓库连接开展预测性分析

    IBM SPSS Modeler 提供预测性分析,可帮助您发现数据模式,提高预测准确性,并改进决策.本教程演示了在 Watson Studio 上使用 SPSS Modeler 的端到端流程:在 Db ...

  5. mysql5.7.25数据库安装

    环境:centos 7.2 下载yum包:https://dev.mysql.com/downloads/repo/yum/ 安装步骤(参考地址): 1.安装rpm包 rpm -Uvh mysql80 ...

  6. 数据库发展史2--数据仓库

    回顾数据仓库的发展历程,大致可以将其分为几个阶段:萌芽探索到全企业集成时代.企业数据集成时代.混乱时代--"数据仓库之父"间的论战.理论模型确认时代以及数据仓库产品百家争鸣时代. ...

  7. 数据库笔记整理--基于《数据库系统概论》第五版王珊一书|复习提纲和错题整合

    数据库原理复习大纲 第一章 数据库概述 1.1 概述 1.基本概念 数据库(DB).数据库管理系统(DBMS).数据库系统(DBS)概念 数据库是存储在计算机内.有组织的.可共享的数据集合. 数据库管 ...

  8. 沈师 数据库原理 PTA 填空题 无答案版

    答案链接:https://blog.csdn.net/a2272062968/article/details/117713227 1.1是长期存储在计算机内有组织.可共享的大量数据的集合. 数据模型的 ...

  9. PostgreSql数据库介绍和使用

    数据库背景 由Michael Stonebraker教授领导的POSTGRES项目是由防务高级研究项目局(DARPA).陆军研究办公室(ARO).国家科学基金(NSF) 以及 ESL, Inc 共同赞 ...

最新文章

  1. 使用javascript开发2048
  2. Python的隐藏功能
  3. 转: MySQL 赋予用户权限(grant %-远程和localhost-本地区别)
  4. MySQL(一)面试集合
  5. 阶段3 3.SpringMVC·_06.异常处理及拦截器_4 SpringMVC拦截器之介绍和搭建环境
  6. AD09 pcb绘制技巧笔记
  7. 按键精灵文字识别插件_按键精灵课程学习目录
  8. Axure如何实现标签切换功能
  9. 学完了Hadoop,我总结了这些重点
  10. If you insist running as root, then set the environment variable RUN_AS_USER=root before running thi
  11. 关于存储单元、寻址范围的问题
  12. 第二十三天 小丁再战链表
  13. 创建React + Ts项目
  14. 知道经纬度来调高德地图的官网API来获取所在的位置(逆地理编码)
  15. 第二课:创建三层神经网络解决非线性问题
  16. Docker基础学习
  17. 2018-11-21 枷锁
  18. TREC Real-Time Summarization Track
  19. MATLAB电力系统仿真好用吗,MATLAB电力系统仿真
  20. java 汽车加速_汽车加速没劲怎么办?四个简单的方法教你提升汽车动力!

热门文章

  1. 简单的信誉算法 js处理
  2. 使用Tornado实现Ajax请求
  3. zend server 配置问题 ZendEnablerConf.xml
  4. Excel生成报表之解决方案--设置单个单元格格式
  5. 一步一步学Silverlight 2系列(4):鼠标事件处理
  6. DATAGUARD 三种保护模式
  7. ORACLE 10046 Trace
  8. RecyclerView的使用和样式
  9. java.io.IOException: Unable to open sync connection!的解决方案
  10. android 访问https服务器