基本查询

查询所有列   ( 关键字 *)

select * from 表名;

查询指定列  

select 列1,列2,列n from 表名;
select `id`,`name`,`age`,`gender` from `student`;
select `id`,`name`,`age` from `student`;

然后我们选择出来的列如果是有很多条一样的,完全重复的记录只要它显示一条

我们需要在这个列的前面加上关键字 distinct

 列的运算

-- 查询给所有员工工资加1000的结果
select id,name,sal+1000 from employee;
select `id`,`name`,`age`*10 from student;

实例:

表名为·123· 

 

    

 注意事项:

对于null的加减乘除 结果都是null

       

如果要处理null的值,用到了IFNULL函数,如果参数1是null,就返回第二个参数。。。。。         

 在mysql中处理字符串时,对字符串进行加减乘除,是将字符串当成0来看作的。。。

 

别名

select 列名1 (as) 别名1,列名2 (as) 别名2 from 表名;
select `id` `编号`,`name` `名字`,ifnull(`age`,0) as `age` from `student` as s;

这个AS不一定要写 ,可以有AS也可以没有AS。。。。。

条件查询 (where)

-- 条件控制  select * from 表名 where 列名=指定值;
select * from student where id = 3;
select * from student where id in (1,3,7);
select * from student where id >5 ;
select * from student where id between 3 and 7 ;
select * from student where id between 6 and 7 or age > 20;

模糊查询  (where  _    %)

select * from student where name like '张_'; 
select * from student where name like '张%';

 

posted on 2023-04-20 15:09  不是小朋友L  阅读(36)  评论(0)    收藏  举报

导航