LOFTER for ipad —— 让兴趣,更有趣

点击下载 关闭
数据库应用与设计实验答案(4)
吴创鹏 2019-06-07

实验4:数据查询

(1)select distinct 工资from wcp.职工(去掉重复)

 

select all 工资from wcp.职工(不去掉重复)

 

(2)select * from wcp.仓库

 

(3)select 职工号from wcp.职工where 工资>1000

 

(4)select 仓库号from wcp.职工where 工资>1000

 

(5)select 职工号from wcp.职工where 仓库号='AA1111' OR 仓库号='AA1112' and 工资<1300

 

(6)select * from wcp.职工where 工资between 1000 and 1300

 

(7)select * from wcp.供应商

 


(8)select * from wcp.仓库where 城市!='广州'



 


(9)select * from wcp.订购单where 供应商号is null

 

说明:订购单表中没有供应商号为空的元组

(10)select * from wcp.订购单where 供应商号is not null

 


(11)select * from wcp.职工order by 工资asc

 


(12)select * from wcp.职工order by 仓库号asc ,工资desc

 

(13)

select 职工号,城市

from wcp.仓库join wcp.职工

on 仓库.仓库号=职工.仓库号

where 工资>1000

 

(14)

select 职工号,城市from wcp.职工join wcp.仓库

on 职工.仓库号=仓库.仓库号

where 面积>50

 


(16)select * from wcp.仓库cross join wcp.职工

 


(17)

select  * from wcp.仓库cross join wcp.职工 where 仓库.仓库号=职工.仓库号

 

(18)

select 供应商.供应商号,供应商名,订购单号,订购日期from wcp.供应商join wcp.订购单

on 供应商.供应商号=订购单.供应商号

 

(19)

select 供应商.供应商号,供应商名,订购单号,订购日期from wcp.供应商left join wcp.订购单

on 供应商.供应商号=订购单.供应商号

 

(20)

select 供应商.供应商号,供应商名,订购单号,订购日期from wcp.供应商right join wcp.订购单

on 供应商.供应商号=订购单.供应商号

 

(21)

select 供应商.供应商号,供应商名,订购单号,订购日期from wcp.供应商full join wcp.订购单

on 供应商.供应商号=订购单.供应商号

 

(22)

select 城市from wcp.仓库where 仓库号in (select 仓库号from wcp.职工where 工资=1101.1000)

 

(23)select * from wcp.仓库where 仓库号not in (select 仓库号from wcp.职工where 工资<=1000)

 

(24)

select * from wcp.职工where 工资=(select 工资from wcp.职工where 职工号='AA111111')

 

(25)


select 城市from wcp.仓库where 仓库号

in (select 仓库号from wcp.职工where 职工号in 

(select 职工号from wcp.订购单where 供应商号in 

(select 供应商号from wcp.供应商where 地址='广州')))


 

(26)

连接查询:

select 供应商名from wcp.供应商join wcp.订购单

on 供应商.供应商号=订购单.供应商号

join wcp.职工on 订购单.职工号=职工.职工号

join wcp.仓库on 职工.仓库号=仓库.仓库号

where 地址='广州' and 城市='广州'

 

嵌套查询:

select 供应商名from wcp.供应商where 地址='广州' and 供应商号in

(select 供应商号from wcp.订购单join wcp.职工on 订购单.职工号=职工.职工号

join wcp.仓库on 职工.仓库号=仓库.仓库号where 城市='广州')

 

(27)

select 仓库号from wcp.仓库where 仓库号in 

(select 仓库号from wcp.职工where 工资>any

(select 工资from wcp.职工join wcp.仓库

on 职工.仓库号=仓库.仓库号

where 仓库.仓库号='AA1111')and 仓库号!='AA1111')


(28)select 仓库号from wcp.仓库where 仓库号in 

(select 仓库号from wcp.职工where 工资>=all(

select 工资from wcp.职工where 仓库号='AA1111'))

 


(29)

select * from wcp.订购单a where 金额=

(select max(金额) from wcp.订购单b where a. 职工号= b.职工号) order by 职工号asc

 

(30)

select * from wcp.仓库where 仓库号=(select 仓库号from wcp.职工where 职工号is null)

 


(31)

select * from wcp.仓库where not exists(select* from wcp.职工where 职工号is null and 职工.仓库号=仓库.仓库号)

 

(32)


select count(distinct 城市) from wcp.仓库where 城市is not null

 

(33)select sum(工资) from wcp.职工

 


(34)

select sum(工资) from wcp.仓库join wcp.职工on 仓库.仓库号=职工.仓库号where 城市='广州' or 城市='深圳'

 

(35)

select avg(面积) from wcp.仓库where 仓库号not in (select 仓库号from wcp.职工where 工资<1000)

 

(36)

select max(金额) from wcp.订购单where 职工号in

(select 职工号from wcp.职工where 工资>1000)

 

(37)select  仓库号,avg(工资) from wcp.职工group by 仓库号

 

(38)

select 仓库号,max(金额),min(金额),avg(金额) 

from wcp.订购单join wcp.职工

on 订购单.职工号=职工.职工号

group by 仓库号

 


(39)

select 订购单.订购单号,avg(金额) from wcp.订购单join wcp.订单明细

on 订购单.订购单号=订单明细.订购单号

group by 订购单.订购单号

having count(订购单.订购单号)>=5

 

(42)

select * from wcp.订购单

compute sum(金额),avg(金额)


推荐文章
评论(0)
分享到
转载我的主页