mysql基础一(判断,条件等)

1.别名

select name as stu_name from student ;

注:as stu_name 是别名

 

2.去重

select DISTINCT classroom from student ;

注:这里使用 DISTINCT 关键字可以去除重复的数据

 

3.连接字符串

select CONCAT(firstName,lastName) from student ;

注:CONCAT可以把两个字符连接起来

 

4.判断字段是否为空

select IFNULL(score,0) , score  from student;

注:在字段前面加上 IFNULL, 当score 是null的时候自动转为0,如果不为null取得原值

 

5.in关键字

select stu_name from student where stu_name IN('jim','hanmeimei','lilei')

注:IN 关键字是判断某值是否存在列表中

 

6.is null 判断

select stu_name,score from student where score is null ;

注:注意这里用score=null 是判断不出来的

 

7.<> 这是不等于的符号

 

8.like '%%' 指的是查询所有,但是如果字段中有null 值的话,这条记录查不出来

select * from student;
select * from student where stu_name like '%%' and score like '%%';

注:注意上面两条语句查询的结果不一样

 

9.not between and  不在哪两个值之间的数据,与between and 相反

 

 

 

 

 


posted @ 2020-12-01 23:33  呆马and鸽子  阅读(219)  评论(0编辑  收藏  举报