Mysql知识
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Mysql知识,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2272字,纯文字阅读大概需要4分钟。
内容图文
![Mysql知识](/upload/InfoBanner/zyjiaocheng/906/da126a68a9ad4e46a7ed45c52ed35255.jpg)
1,create table student1 as select *from student;///除了约束都能复制
2,alter table change name name1;//修改列名
3,rename table student to studet1;//修改表名
4, select distinct leval from student; //消除重复,distinct紧跟select 只写一次。
5.select name ,sal+500 from EMP;//只查询时加并非修改
6,select empno 员工编号,ename 员工姓名 from emp;//查询时显示列别名:
7,between ...and...//闭区间
8,like '李%'//%任意w位数的字符串; like'%李%'; _占一位字符 //模糊查询
9,null 与0//有本质区别的挂科。查空值:is null.
10,select *from emp order by sal desc,empon ASC;//先按照sal降序排列,相等的话按empon升序。
11,select *from emp where deptno=30 order by sal desc;//先选后排
12,日期类型的查询:select *from emp where heirdate='1981-12-03';
13,select mod(5,3)//取余=2;orcle:select mod(5,3)from +虚表
14,select round(100.56,1)//四舍五入=100.6;
select ename,sal,round(sal ,-2)from emp;//把工资四舍五入到百位。
15,字符函数
获取字符串:substraing
select substraing('I Love you',3,4);
select substraing(ename,1,3)from emp;//从第一个字母开始截取名字的连续三个字母。
select ename concat()
16,日期函数
select curdate();//当前系统日期(年月日);
select curtime();//当前系统时间(时分秒);
select DATE_FORMAT(now(),'%y-%m-%s %h:%i:%s')//自定义输出格式
年-月-日 时:分:秒
17,ifnull(e1,e2)//如果e1不为空则取e1,否则取e2的数值;
例如:ifnull(null,1)=1;
ifnull (1,2)=1;
18,多行函数
count();
(1),count(*)
(2),count(列名)//过滤空属性值。
(3),select count(distinct job)from emp;//消除重复职位后的记录个数(种类);
sum();
select avg(ifnull(comm,0))from emp;//查平均奖金。
max();
可用于日期,min:日期早 max:晚
min();
19,分组
group by(列名)
select depton,sum(sal)from emp group by depton;//按一个属性分组:查询每个部门各自的总收入
select depton,job ,count(*)from emp group by deptno,job;//按两个属性分组截图
//orcle 报错
select后面可以写:分组的列,主函数;
select deptno ,sum(sal)from emp group by deptno having sum(sal)>10000;
/*******************************************************************
where 在分组前过滤,having 在分组后过滤。
每个部门员工工资超过1500有两人的部门。
什么在分组前做,什么在分组后做
*******************************************************************/
select deptno ,count(*)from emp where sal>1500 group by deptno
having count(*)>2;//为什么分组前要
内容总结
以上是互联网集市为您收集整理的Mysql知识全部内容,希望文章能够帮你解决Mysql知识所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。
来源:【匿名】