1.在mysql中+号的使用,在mysql中的+号仅仅只有一个功能;
- 当两个操作数都为数值时,做加法运算
- 当一个为字符串时,转成功则做加法,失败则将字符串当做零。
- 当其中一方为null时,则结果为null。
2.concat 如何将二个字段连接成一个字段,
select concat (‘a’,‘b’) as result
- ifnull函数,可以让为null的取一人值,解决null同任何数相加都为空的麻烦。
-
is null ,is not null可以用来判断表中的数据是否为null,
也可以用安全等于<=> ,可以用来避免为据查询的数值为null而产生的后果。
where salary = null (错误写法)
where salary <=> null (正确)
比较:
is null 用于判断为数值为null的
<=>即可用于判断数值为null又可以判断普通数值,但可读性差,用的比较少
面试题:
-
distinct :distinct 的做用是去重
distinct前面不能写其它字段
select age, distinct name from user
这样会导致产生的数据条数不一致,而产生错误。
应该这样写
select distinct age,name from user
这样写的话distinct可以同时做用于age 和name 联合去重,不会产生错误。 -
length() 此函数可以得到字段的长度,也可以通过字段长度进行排序。
select length(last-name) len from employees order by length(last-naem) desc;