mysql练习题3
USE day44; -- 1 查出所有员工的名字,薪资,格式为
-- <名字:egon> <薪资:3000>
SELECT '姓名:',name,'薪资:',salary from employee; -- 2 查出所有的岗位(去掉重复)
select distinct(post) from employee; -- 3 查出所有员工名字,以及他们的年薪,年薪的字段名为annual_year
SELECT name,salary*12 as annual_year from employee; -- 1. 查看岗位是teacher的员工姓名、年龄
select name,age from employee where post='teacher'; -- 2. 查看岗位是teacher且年龄大于30岁的员工姓名、年龄
select name,age from employee where post='teacher' and age>30; -- 3. 查看岗位是teacher且薪资在9000-1000范围内的员工姓名、年龄、薪资
select name,age,salary from employee
where post='teacher' and salary BETWEEN 9000 and 10000; -- 4. 查看岗位描述不为NULL的员工信息
select * from employee where not null; -- 5. 查看岗位是teacher且薪资是10000或9000或30000的员工姓名、年龄、薪资
select * from employee where post='teacher' and salary in (10000,9000,30000); -- 6. 查看岗位是teacher且薪资不是10000或9000或30000的员工姓名、年龄、薪资
select * from employee where post='teacher' and salary not in(10000,9000,30000); -- 7. 查看岗位是teacher且名字是jin开头的员工姓名、年薪
select * from employee where name like 'jin%'; -- 1. 查询岗位名以及岗位包含的所有员工名字
select post,group_concat(name) from employee group by post; -- 2. 查询岗位名以及各岗位内包含的员工个数
select post,count(id) from employee group by post; -- 3. 查询公司内男员工和女员工的个数
select sex,count(id) from employee group by sex; -- 4. 查询岗位名以及各岗位的平均薪资
select post,avg(salary) from employee group by post; -- 5. 查询岗位名以及各岗位的最高薪资
select post,max(salary) from employee GROUP BY post; -- 6. 查询岗位名以及各岗位的最低薪资
select post,min(salary) from employee GROUP BY post; -- 7. 查询男员工与男员工的平均薪资,女员工与女员工的平均薪资
select sex,avg(salary) from employee group by sex; -- 1. 查询各岗位内包含的员工个数小于2的岗位名、岗位内包含员工名字、个数
select post,group_concat(name),count(id) from employee group by post having count(id)<2; -- 3. 查询各岗位平均薪资大于10000的岗位名、平均工资
select post,avg(salary) from employee group by post having avg(salary)>10000; -- 4. 查询各岗位平均薪资大于10000且小于20000的岗位名、平均工资
SELECT post,avg(salary) from employee group by post
having avg(salary)>10000 and avg(salary)<20000; -- 1. 查询所有员工信息,先按照age升序排序,如果age相同则按照hire_date降序排序
select * from employee order by age asc,hire_date desc; -- 2. 查询各岗位平均薪资大于10000的岗位名、平均工资,结果按平均薪资升序排列
select post,avg(salary)as a from employee group by post
having avg(salary)>10000 order by a asc; -- 3. 查询各岗位平均薪资大于10000的岗位名、平均工资,结果按平均薪资降序排列
select post,avg(salary) a from employee group by post
having avg(salary) >10000 order by a desc; -- 查看所有员工中名字是jin开头,n或者g结果的员工信息
select * from employee where name REGEXP '^jin.*[n|g]$';
mysql练习题3的更多相关文章
- MySQL练习题
MySQL练习题 一.表关系 请创建如下表,并创建相关约束 二.操作表 1.自行创建测试数据 2.查询“生物”课程比“物理”课程成绩高的所有学生的学号: 3.查询平均成绩大于60分的同学的学号和平均成 ...
- MySQL练习题参考答案
MySQL练习题参考答案 2.查询“生物”课程比“物理”课程成绩高的所有学生的学号: 思路: 获取所有有生物课程的人(学号,成绩) - 临时表 获取所有有物理课程的人(学号,成绩) - 临时表 根据[ ...
- s15day12作业:MySQL练习题参考答案
MySQL练习题参考答案 导出现有数据库数据: mysqldump -u用户名 -p密码 数据库名称 >导出文件路径 # 结构+数据 mysqldump -u用户名 -p ...
- Python/ MySQL练习题(一)
Python/ MySQL练习题(一) 查询“生物”课程比“物理”课程成绩高的所有学生的学号 SELECT * FROM ( SELECT * FROM course LEFT JOIN score ...
- python/MySQL练习题(二)
python/MySQL练习题(二) 查询各科成绩前三名的记录:(不考虑成绩并列情况) select score.sid,score.course_id,score.num,T.first_num,T ...
- python 全栈开发,Day65(MySQL练习题,参考答案)
一.MySQL练习题 一.表关系 请创建如下表,并创建相关约束 二.操作表 1.自行创建测试数据 2.查询“生物”课程比“物理”课程成绩高的所有学生的学号.ps:针对的是自己的生物成绩比物理成绩高,再 ...
- mysql 练习题答案
一 题目 1.查询所有的课程的名称以及对应的任课老师姓名 2.查询学生表中男女生各有多少人 3.查询物理成绩等于100的学生的姓名 4.查询平均成绩大于八十分的同学的姓名和平均成绩 5.查询所有学生的 ...
- mysql练习题练习
1.数据库是按照原文制作的,表格结构一样具体存储的数据有些差异 原文地址:MySQL练习题 原答案地址:MySQL练习题参考答案 2.查询“生物”课程比“物理”课程成绩高的所有学生的学号: selec ...
- MySQL练习题及答案(复习)
新建一个叫做 review 的数据库,将测试数据脚本导进去.(可以使用Navicat查询功能) /* Navicat MySQL Data Transfer Source Server : DB So ...
- mysql练习题-查询同时参加计算机和英语考试的学生的信息-遁地龙卷风
(-1)写在前面 文章参考http://blog.sina.com.cn/willcaty. 针对其中的一道练习题想出两种其他的答案,希望网友给出更多回答. (0) 基础数据 student表 +-- ...
随机推荐
- poj1942(求组合数)
题目链接:http://poj.org/problem?id=1942 题意:实际上这道题就是求C(n+m,n). 思路:n.m的范围在unsigned中,所以不能递推计算组合数,可以采用公式C(a, ...
- 188. Best Time to Buy and Sell Stock IV (Array; DP)
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- 网页请求get方式
方法都是博客中的大神写的,谢谢各路大神. 方法一:(亲测有效) //Get请求方式 private string RequestGet(string Url) { string PageStr = s ...
- PHP20-challenge12
看下eval+var_dump的妙用. eval会执行括号中的内容:var_dump中内容是字符串时输出的模式是 string(x) "xxxx".如果他俩结合,是可以很好 ...
- maven 创建project
------------------------------maven3常用命令--------------------------- 1.常用命令 1)创建一个Project mvn archety ...
- centos 命令学习
关机&重启 shutdown -h 10 #计算机将于10分钟后关闭,且会显示在登录用户的当前屏幕中 shutdown -h now #计算机会立刻关机 shut ...
- asp.net core webapi 日期返回中出现字母T
全局配置 在Startup文件中修改 // This method gets called by the runtime. Use this method to add services to the ...
- vue2.0后台系统
参考网址: http://www.cnblogs.com/linxin/p/6509897.html
- Sublime Text3 常用快捷键必看
Sublime Text3 常用快捷键必看 https://blog.csdn.net/md1688/article/details/53043525
- Jmeter常用脚本开发之Junit Request
说明:Junit Request就是把Junit测试框架的自动化用例在jmeter上执行 步骤: 1.创建Java工程,编写Junit自动化测试用例 2.然后把用例打成jar包,复制到Jmter的li ...