第07章_单行函数
讲师:尚硅谷-宋红康(江湖人称:康师傅)
官网:http://www.atguigu.com
SELECT now()
FROM DUAL;
SELECT employee_id,last_name,salary,salary*1.2 "new salary"
FROM employees;
SELECT last_name,LENGTH(last_name)
FROM employees
ORDER BY last_name DESC;
select concat(employee_id,',',last_name,',',salary) "OUT_PUT"
FROM employees;
SELECT SYSDATE(),DATEDIFF(SYSDATE(),hire_date),DATEDIFF(SYSDATE(),hire_date)/365 "work_year"
FROM employees
ORDER BY work_year DESC;
SELECT last_name,hire_date,department_id
FROM employees
WHERE DATE_FORMAT(hire_date,'%Y') >= '1997'
AND department_id IN (80,90,110)
AND commission_pct IS NOT NULL;
SELECT last_name,hire_date
FROM employees
WHERE DATEDIFF(now(),hire_date)>10000;
SELECT CONCAT(last_name,' earns ',TRUNCATE(salary,0),' monthly but wants ',TRUNCATE(salary*3,0)) "Dream Salary"
FROM employees;
# 9.使用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 Last_name,job_id Job_id,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'
ELSE 'F'
END 'grade'
FROM employees;