Left (A,4)从左边开始截取4个字符
Right(A,4)从右边开始截取4个字符
1987-04-19 -》1987
select left('1987-04-19',4);
###(1)获取员工的入职年份
select ename,hiredate,left(hiredate,4) from emp;
###(2)获取员工的入职工龄
select ename,hiredate,2021 - left(hiredate,4) from emp;
2024-03-12 20:42:56
Left (A,4)从左边开始截取4个字符
Right(A,4)从右边开始截取4个字符
1987-04-19 -》1987
select left('1987-04-19',4);
###(1)获取员工的入职年份
select ename,hiredate,left(hiredate,4) from emp;
###(2)获取员工的入职工龄
select ename,hiredate,2021 - left(hiredate,4) from emp;