4.25 数据库 仓库例题
生活随笔
收集整理的這篇文章主要介紹了
4.25 数据库 仓库例题
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
--倉庫表:
--倉庫號 城市 面積
--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元范圍內(nèi)的職工信息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.找出供應商所在地的數(shù)目。
select *from gongyingshang
select count(*),dizhi from gongyingshang group by dizhi
--17.求支付的工資總數(shù)
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'
?
--?
轉(zhuǎn)載于:https://www.cnblogs.com/w-wz/p/4456959.html
總結(jié)
以上是生活随笔為你收集整理的4.25 数据库 仓库例题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ArcGIS学习记录—KMZ KML与S
- 下一篇: 新公司编码规范