select concat('Hello','MySQL');
select lower('Hello');
select upper('Hello');
select lpad('01',5,'-');
select rpad('01',5,'-');
select trim(' hello world ');
select substring('helloworld',1,5);
select ceil(1.5);
select floor(1.2);
select mod(3,2);
select rand();
select round(2.34,2);
select round(2.345,1);
select lpad(round(rand()*1000000,0),6,'0');
select curdate();
select curtime();
select now();
select year(now());
select month(now());
select year(now());
select date_add('2021-10-21',INTERVAL 70 day);
select date_add('2021-10-21',INTERVAL 70 MONTH );
select DATE_ADD('2021-10-21',INTERVAL 70 YEAR );
select datediff('2011-2-11','2000-3-4'); # date1 - date2
select datediff('2011-2-11','2021-3-4');
select if(true,'hello','world');
select if('1',2,3);
select if(false,0,1);
select ifnull(null,1);
select ifnull(1,2);
select ifnull('ok','default');
select ifnull('','default'); # 空字符串并不代表null
-- >=85,展示优秀;>=60,展示及格;否则,展示不及格
select id,name,
(case when math >= 85 then '优秀' when math >= 60 then '及格' else '不及格' end) as '数学等级',
(case when english >= 85 then '优秀' when english >= 60 then '及格' else '不及格' end) as '英语等级',
(case when chinese >= 85 then '优秀' when chinese >= 60 then '及格' else '不及格' end) as '语文等级'
from score;
-- 需求:查询emp表中的员工姓名和工作地址(北京/上海-->一线城市,其他-->二线城市)
select name,workaddress,
(case workaddress when '北京' then '一线城市' when '上海' then '一线城市' else '二线城市' end) as '工作地址'
from emp;