Mysql中经常会用到查询子句例如where查询语句,它的使用很广泛,下面详解详解where条件下的各种查询
- where子句简单查询
select * from employee; select empno,ename,job as ename_job from employee;
- where精确条件查询
select * from employee where ename='后裔'; select * from employee where sal != 50000; select * from employee where sal <> 50000; select * from employee where sal > 10000;
- where like模糊条件查询
show variables like '%aracter%'; select * from employee where ename like '林%';
- between范围查询
select * from employee where sal between 10000 and 30000; select * from employee where hiredate between '2011-01-01' and '2017-12-1';
- in离散查询语句
select * from employee where ename in ('猴子','林俊杰','小红','小胡');
- mysql清除重复值
select distinct(job) from employee;
- mysql统计查询(mysql聚合函数)
#count(code)或者count(*) select count(*) from employee; select count(ename) from employee; #sum() mysql计算总和 select sum(sal) from employee; #max() mysql计算最大值 select * from employee where sal= (select max(sal) from employee); #avg() mysql计算平均值 select avg(sal) from employee; #min() mysql计算最低值 select * from employee where sal= (select min(sal) from employee); #concat函数: 起到连接作用