ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

mysql语句

2020-02-22 22:05:31  阅读:274  来源: 互联网

标签:语句 ename sal emp mysql deptno where select


1.索引

drop index idx_name on user;

create index idx_name on user;

show index from user;

2.查询

select * from user limit 0,10;

select * from user order by id desc,addtime asc;

SELECT DISTINCT JOB FROM T_EMP;

select 10+ifnull(null,0) ;

select * from t_emp where DATEDIFF(now(), hiredate)/365>=39;

select * from t_emp where ename regexp "[a-zA-Z]{4}";

select * from t_emp where ename  regexp "^[\\u4e00-\\u9fa5]{2,4}$";

select avg(sal+ifnull(comm,0))  from t_emp;

select deptno,round(avg(sal)) from t_emp group by deptno;

select deptno,group_concat(ename),count(*) from t_emp where sal>2000 group by deptno;

select deptno from t_emp group by deptno having avg(sal)>2000;

update t_emp e,(select avg(sal) as avg from t_emp) t set e.sal=e.sal+150 where e.sal<t.avg;

select ename from t_emp where deptno=(select deptno from t_emp where ename="SCOTT") and ename!="SCOTT";(效率低)

select t2.ename from t_emp t1,t_emp t2 where t1.deptno=t2.deptno and t1.ename="SCOTT" AND t2.ename!="SCOTT";(效率高)

select * from t_emp e,(select avg(sal) avg from t_emp) t where e.sal<t.avg;

SELECT * FROM t_emp  where sal>= ANY
(select sal from t_emp where ename in("ALLEN","MARTIN"));

SELECT * FROM t_emp  where sal>= ALL
(select sal from t_emp where ename in("ALLEN","MARTIN"));

3.函数

 abs()绝对值  floor()向下取整  ceil()向上取整  round()四舍五入 power(2,3)幂函数 log(7,3) ln(10)对数;

select now(),curdate(),curtime();

select date_format(now(),"%D")

select  COUNT(*) from t_emp where date_format(`hiredate`,"%Y")=1981 AND DATE_FORMAT(hiredate,"%m")<=6;

SELECT DATE_ADD(NOW(),INTERVAL 15 DAY);某个时间加上偏移量后的时间。

select datediff(now(),"1990-2-16");计算两个日期相差多少天。

 

4.加密

select hex(aes_encrypt("hello","abc123"));加密
select  aes_decrypt(unhex("2345ABEA5CEADE0FD427E1670D9BED01"),"abc123");解密

junfeng525 发布了17 篇原创文章 · 获赞 0 · 访问量 9346 私信 关注

标签:语句,ename,sal,emp,mysql,deptno,where,select
来源: https://blog.csdn.net/qq_26347283/article/details/104383586

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有