五、DQL语言
文章目录
5.5.2.查询字符串
5.5.3.查询表达式
5.5.4.查询函数
5.5.5.起别名
select 100*12 as 乘法结果;
#先进入myemployees库
use myemlpoyees;
select last_name as 姓,first_name as 名 from employees;
5.5.6.去重名
5.5.7.加号的作用
-
在MySQL中加号只有运算符作用
-
MySQL作用分类:
-
整型
+整型
------加法运算 -
字符串
+整型
- 自动将字符串转换为整型
成功了
的话,继续加法运算 - 自动将字符串转换为整型
失败了
的话,等于0+整型
并计算出结果
- 自动将字符串转换为整型
-
null
参与下,只要两个数中又有个是null
结果必定为null
SELECT 'yanyu'+23;
SELECT NULL+23;
SELECT '12'+12;
- 转换失败,等于
0+23
- 有
null
参与结果为null
转换成功- 将”姓“和”名“连接起来
select concat(last_name,first_name) as 名字 from employees;
desc departments;
#显示departments这个表的结构
5.5.8.判断某一项是否为NULL
select ifnull(commission_pct,0) as 奖金率,commission_pct from employees;
/*
如果commission_pct为NULL,则返回值为0
*/
SELECT CONCAT(`last_name`,`first_name`,`email`,IFNULL(`commission_pct`,0)) AS "put into" FROM employees;