码迷,mamicode.com
首页 > 数据库 > 详细

实验四 数据库查询

时间:2018-12-23 22:03:27      阅读:1125      评论:0      收藏:0      [点我收藏+]

标签:员工   ati   显示   bsp   学历   min   img   .com   实验   

1、  查询Departments表中的所有记录;

Use  yggl;

Select  *  from  departments;

 

技术分享图片

 

 

2、  查询Employees表中员工的姓名,地址和电话;

Select name,address,phonenumber

From employees;

 

技术分享图片

 

 

3、  查询Employees表中员工的部门号和性别,要求消除重复行;

Select distinct departmentid,sex

From employees;

 

技术分享图片

 

4、  查询EmployeeID为000001的员工地址和电话,要求显示列名为address、telephone;

Select address as address,phonenumber as telephone

From employees

Where employeeid = ‘000001’;

 

 

技术分享图片

 

5、  查询Employees表中员工的姓名和性别,要求性别为1时显示为“男”,为0时显示为“女”;

Select name,

Case

When  sex=1  then ‘男

When  sex=0  then ‘女

End as sex

From employees;

 

技术分享图片

 

6、  计算Salary表中所有员工收入的平均值、最大值和最小值;

Select  avg(income),max(income),min(income)

From salary;

技术分享图片

 

 

7、  计算所有员工的总支出;

Select sum(outcome) as ‘总支出

From salary;

技术分享图片

 

 

8、  计算员工总数;

Select  count(*)  as ‘员工总数

From  employees;

 技术分享图片

 

 

9、  显示女员工的地址和电话;

Select name as ‘姓名’,address as ‘地址’,phonenumber as ‘电话

From  employees

Where sex =0;

 

技术分享图片

 

10、  查询月收入高于2000元的员工编号;

Select employeeid

From salary

Where income>2000;

 

技术分享图片

 

11、  查询1970年以后出生的员工的姓名和地址;

Select name as’姓名’,address as ‘地址

From employees

Where  birthday >’197-12-31’;

技术分享图片

 

 

12、  查询地址中含有“中山”的员工编号和部门号;

Select name as’姓名’,employeeid as ‘员工编号’,departmentid  as ‘部门号

From employees

Where address like ‘中山%’;

 

技术分享图片

 

13、  查询员工编号中倒数第二个数字为0的姓名、地址和学历;

Select name,address,education

From employees

Where employeeid like ‘%0_’;

技术分享图片

 

 

14、  找出所有收入在2000-3000元之间的员工编号和姓名;

         Select name  as ’姓名’,salary.employeeid  as ‘员工编号

         From employees,salary

Where employees.employeeid=salary.employeeid

And income>2000 and income<3000;

 

技术分享图片

 

 

15、  查询所有在部门“1”或“2” 工作的员工编号。

Select name as’姓名’,employeeid as ‘员工编号

From employees

Where departmentid=1 or departmentid=2;

 

技术分享图片

 

 

 

 

 

 

 

实验四 数据库查询

标签:员工   ati   显示   bsp   学历   min   img   .com   实验   

原文地址:https://www.cnblogs.com/lvwuwa/p/10165572.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!