Live2D

单行函数案例讲解

配套视频见下方网址,相关文件见视频评论区
[尚硅谷MySQL教程](https://www.bilibili.com/video/BV12b411K7Zu)

1.显示系统时间(注:日期+时间)

SELECT NOW();

2.查询员工号,姓名,工资,以及工资提高20%后的结果(new salary)

SELECT employee_id,last_name,salary,salary*1.2 "new salary"
FROM employees;

3.将员工的姓名按首字母排序,并写出姓名的长度(length)

SELECT LENGTH(last_name) 长度,SUBSTR(last_name,1,1) 首字符,last_name
FROM employees
ORDER BY 首字符;

4.做一个查询,产生下面的结果

<last_name> earns monthly but wants <salary*3>
Dream Salary
King earns 24000 monthly but wants 72000

SELECT CONCAT(last_name,' earns ',salary,' monthly but wants ',salary*3) AS "Dream Salary"
FROM employees
WHERE salary=24000;

5.使用case-when,按照下面的条件:

job grade
AD_PRES A
ST_MAN B
IT_PROG C
SA_REP D
ST_CLERK E
产生下面的结果
Last_name Job_id Grade
king AD_PRES A

SELECT last_name,job_id AS job,
CASE job_id
WHEN 'AD_PRES' THEN 'A'
WHEN 'ST_MAN' THEN 'B'
WHEN 'IT_PROG' THEN 'C'
WHEN 'SA_REP' THEN 'D'
WHEN 'ST_CLERK' THEN 'E'
END AS GRADE
FROM employeeS
WHERE job_id = 'AD_PRES';

posted @ 2020-09-23 15:21  xbycf  阅读(223)  评论(0编辑  收藏  举报