简介:详解where条件下的各种查询

- 简单查询

select * from employee;
select empno,ename,job as ename_job from employee;

- 精确条件查询

select * from employee where ename='后裔';
select * from employee where sal != 50000;
select * from employee where sal <> 50000;
select * from employee where sal > 10000;

- 模糊条件查询

show variables like '%aracter%'; 
select * from employee  where ename like '林%';

- 范围查询

select * from employee where sal between 10000 and 30000;
select * from employee where hiredate between '2011-01-01' and '2017-12-1';

- 离散查询

select * from employee where ename in ('猴子','林俊杰','小红','小胡');  

- 清除重复值

select distinct(job) from employee;

- 统计查询(聚合函数)

#count(code)或者count(*)
select count(*) from employee;
select count(ename) from employee;
        
#sum()  计算总和 
select sum(sal) from employee;
        
#max()    计算最大值
select * from employee where sal= (select  max(sal) from employee);
        
#avg()   计算平均值
select avg(sal) from employee;
        
#min()   计算最低值
select * from employee where sal= (select  min(sal) from employee);
        
#concat函数: 起到连接作用
select concat(ename,' 是 ',job) as aaaa from employee;
最后修改:2021 年 08 月 16 日 04 : 21 PM
如果觉得我的文章对你有用,请随意赞赏