系列文章目录
提示:这里可以添加系列文章的所有文章的目录,目录需要自己手动添加
例如:第一章 Python 机器学习入门之pandas的使用
提示:写完文章后,目录可以自动生成,如何生成可参考右边的帮助文档
文章目录
系列文章目录
前言
一、mysql
总结
前言
提示:这里可以添加本文要记录的大概内容:
例如:随着人工智能的不断发展,机器学习这门技术也越来越重要,很多人都开启了学习机器学习,本文就介绍了机器学习的基础内容。
提示:以下是本篇文章正文内容,下面案例可供参考
一、Mysql?
mysql
管理-服务和应用程序-服务
net stop mysql10815
net start mysql10815
mysql -h localhost -P 3306 -u root -p
show databases;
use 库名;
show tables;
show tables from 库名;
select database();
desc 表名;
select username as 用户名,password as 密码 from user;
select salary as "out put" from employees;
去重 select distinct department_id from employees;
IFNULL用法
select IFNULL(commission_pct,0) AS 奖金率,commission_pct from employees;
concat用法
select concat(username,',',username,',',IFNULL(commission_pct,0)) as out_put from employees;
查询部门编号不是在90到110之间,或者工资高于15000的员工信息
select * from employees where not(department_id>=90 and department_id<=110) or salary>15000;
查询员工包含字符a的员工信息
select * from employees where username like '%a%';
查询员工第三个字符为e,第五个字符为a的员工名和工资
select username,salary from employees where username like '__n_e%';
查询员工名中第二个字符为_的员工名
select username from employees where username like '_\_%';
select username from employees where username like '_$_%' ESCAPE '$';指定转义字符
查找job_id(字符串)为 it_prot ad_vp ad_pres 的信息
select username job_id where job_id ='it_prot' or job_id ='ad_vp' or job_id ='ad_pres'
select username job_id where job_id in ('it_prot' ,'ad_vp' ,'ad_pres')
查询没有奖金的员工名和奖金率
select username,commission_pct from employees where commission_pct IS NULL;
select username,commission_pct from employees where commission_pct IS NOT NULL;
查询没有奖金,且工资小于18000的salary,last_name
select salary,last_name from employees where commission_pct is null and salary<18000;
查询employees表中,job_id不为‘IT'或者工资为12000的员工信息
selet * from employees where job_id <> 'IT' or salary=12000;
查看下部门departments表中涉及到的位置编号
select distinct location_id from department;
查看下一下sql语句是不是一样
select * from employees;
select * from employees where username like '%%' and commission_pct like '%%';
select * from employees where username like '%%' or commission_pct like '%%';
12结果不一样,判断字段有没有null
13结果一样
查询员工信息 排序
select * from employees ORDER BY salary DESC;
按姓名长度显示员工的姓名和工资【按函数排序】
select LENGTH(last_name) 字节长度,last_name,salary from employees ORDER BY LENGTH(last_name) DESC;
查询员工信息,要求先按工资升序,再按员工编号降序【按多个字段排序】
select * from employees order by salary ASC,employees_id DESC;
查询员工的姓名和部门号和年薪,按年薪降序 按照姓名升序
select last_name,department_id,salary*12*(1+IFNULL(commission_pct,0)) 年薪 from employees ORDER by
年薪 DESC,last_name ASC;
查询工资不在8000到17000的员工的姓名和工资,按工资降序
select last_name,salary from employees where salary NOT between 8000 and 17000 order by salary desc;
查询邮箱中包含e的员工信息,并按着邮箱的字节数降序,再按着部门号升序
select *,LENGTH(email) from employees where email like '%e%' order by LENGTH(email) desc,department_id ASC;
concat拼接字符串
select concat(last_name,'_',first_name) 姓名 from employees;
upper,lower
将姓变大写,名变小写,然后拼接
select concat(upper(last_name),lower(first_name)) 姓名 from employees;
substr substring
截取从指定索引处后面所有字符
select substr('李莫愁爱上了陆展元') out_put;
截取从指定索引处指定字符串长度的字符
select substr('李莫愁爱上了陆展元',1,3) out_put;
姓名中首字符大写,其他字符小写然后用_拼接,显示出来
select concat(upper(substr(last_name,1,1)),'_',lower(substr(last_name,2))) out_put from employees;
instr返回子串第一次出现的索引,如果找不到返回0
select INSTR('杨不悔爱上了殷六侠','殷六侠') AS out_put;
trim()
select LENGTH(TRIM(' 张翠山 ')) as out_put;
select TRIM('a' from 'aaaa张aa翠山aaa') as out_put;
lpad用指定的字符串实现左填充指定长度
select LPAD('殷素素',10,'*') as out_put;
rpad用指定字符实现又填充指定长度
select RPAD('殷素素',12,'ab') as out_put;
replace替换
select REPLACE('周芷若周芷若张无忌','周芷若','赵敏') as out_put;
返回当前系统日期+时间
select NOW();
返回当前系统日期,不包含时间
select CURDATE();
返回当前时间,不包含日期
select CURTIME();
distinct 去重
select SUM(DISTINCT salary),SUM(salary) from employees;
select COUNT(DISTINCT salary),COUNT(salary) from employess;
查询员工表中的最大入职时间和 最小入职时间的相差天数
select DATEDIFF(MAX(hiredate),MAX(hiredate)) DIFFRENCE from employees;
查询每个工种的最高工资
select MAX(salary),job_id from employees GROUP BY job_id;
查询每个位置上的部门个数
select COUNT(*),location_id from departments GROUP BY location_id;
查询邮箱中包含a字符的,每个部门的平均工资
select AVG(salary),department_id from employees where email like '%a%' GROUP BY department_id;
查询有奖金的每个领导手下员工的最高工资
select MAX(salary),manager_id from employees where commission_pct IS NOT NULL GROUP BY manager_id;
总结
提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了mysql的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。