|
|
Posted on 4/16/2015 7:11:16 PM
|
|
|

1. There is an order management database, which includes warehouse table, employee table, order form and supplier table as follows: Warehouse table (warehouse number, city, area) Employee table (warehouse number, employee number, salary) Purchase order form (employee number, supplier number, purchase order number, order date) Supplier Table (Supplier Number, Supplier Name, City) Please use SQL statements to complete the following operations (3 points for each question from 1-12, 4 points for 13 questions, a total of 40 points). : 1. Retrieve all wage values from the employee relationship, and require that there are no duplicate values in the results. 2. Search for employee numbers with salaries of more than 1,230 yuan and their city. 3. Search the employee number of the warehouse with an area greater than 400 and the city where these employees work. 4. Find out which cities have at least one warehouse with a salary of 1250 yuan 5. Search the information of warehouses where the salary of all employees is more than 1210 yuan. 6. Sort by warehouse number in ascending order, then in descending order of salary and output all employee information. 7. Seek the sum of the wages of warehouse workers in Beijing and Shanghai. 8. Obtain the maximum salary value of employees working in the WH2 warehouse. 9. Obtain the average salary of each warehouse with at least two employees. 10. Retrieve all supplier information not in Beijing. 11. List the purchase order information with the highest total amount handled by each employee. 12. Retrieve information on which warehouses do not have employees. 13. Search for the warehouse number of the employee's salary greater than or equal to the salary of any employee in the WH1 warehouse
SQL code:
- use master
- --删除数据库
- if exists (select * from sysdatabases where name='订货管理')
- DROP database 订货管理
- GO
- --创建数据库
- CREATE DATABASE 订货管理
- GO
- --切换数据库
- USE 订货管理
- Go
- --1/创建仓库表(仓库号,城市,面积)
- create table 仓库表
- (
- 仓库号 char(4) primary key,
- 城市 varchar(4) not null,
- 面积 int
- )
- go
- --2/创建供应商表(供应商号,供应商名,城市)
- create table 供应商表
- (
- 供应商号 char(2) primary key,
- 供应商名 char(2),
- 城市 varchar(10)
- )
- Go
- --3/创建职工表(仓库号,职工号,工资)
- create table 职工表
- (
- 仓库号 char(4) not null references 仓库表(仓库号),
- 职工号 char(2) primary key,
- 工资 int
- )
- Go
- --4/创建订购单表(职工号,供应商号,订购单号,订购日期)
- create table 订购单表
- (
- 职工号 char(2) not null references 职工表(职工号),
- 供应商号 char(2) references 供应商表(供应商号),
- 订购单号 char(2) primary key,
- 订购日期 datetime
- )
- Go
- --1、 从职工关系中检索所有工资值,要求结果中没有重复值。
- select 职工号,工资 from 职工表
- --2、 检索工资多于1230元的职工号和他们所在的城市。
- select 城市,职工号 from 仓库表
- inner join 职工表 on 仓库表.仓库号=职工表.仓库号
- where 工资>1230
- --3、 检索工作在面积大于400的仓库的职工号以及这些职工工作所在的城市。
- select 职工号,城市 from 职工表
- inner join 仓库表 on 职工表.仓库号=仓库表.仓库号
- where 面积>400
- --4、 检索出哪些城市至少有一个仓库的职工工资为1250元
- select 城市 from 仓库表 where 仓库号 in
- (select 仓库号 from 职工表 where 工资=1250)
- --5、 检索所有职工的工资都多于1210元的仓库的信息。
- select * from 仓库表 where 仓库号 in
- (select 仓库号 from 职工表 where 工资>=1210)
- --6、 先按仓库号升序排序,再按工资降序排序并输出全部职工信息。
- select * from 职工表 order by 仓库号,工资 DESC
- --7、 求北京和上海的仓库职工的工资总和。
- select sum(工资) from 职工表 where 仓库号 in
- (select 仓库号 from 仓库表 where 城市='北京' or 城市='上海')
- --8、 求在wh2仓库工作的职工的最高工资值。
- select MAX(工资) from 职工表 where 仓库号='wh2'
- --9、 求至少有两个职工的每个仓库的平均工资。
- select 仓库号,AVG(工资) as 职工平均工资 from 职工表
- group by 仓库号
- having COUNT(职工号)>=2
- --10、 检索出不在北京的全部供应商信息。
- select * from 供应商表 where 城市<>'北京'
- --11、 列出每个职工经手的具有最高总金额的订购单信息。
- --12、 检索哪些仓库中还没有职工的仓库的信息。
- select * from 仓库表 where 仓库号 in
- (select 仓库号 from 仓库表
- Except
- select 仓库号 from 职工表)
- --13、 检索有职工的工资大于或等于wh1仓库中任何一名职工工资的仓库号
- select distinct 仓库号 from 职工表
- where 工资 >= (select min(工资) from 职工表 where 仓库号='wh1')
Copy code
|
Previous:I know that there are many painting masters in our school, but they don't visit this forum, so I just post some of my paintingsNext:asp.net how do I get all controls to show in play?
|