MYSQL数据库SQL语句练习实验 EXERCISES 4 DATES

  1. Select the name, job, and date of hire of the employees in department 20. (Format the HIREDATE column to MM/DD/YY)
    Select ename,job,date_format(hiredate,' %m/%d/%Y') from emp2019274072 where deptno=20;

    MYSQL数据库SQL语句练习实验 EXERCISES 4 DATES_第1张图片

     

  2. Then format the HIREDATE column into DoW (day of the week), Day (day of the month), MONTH (name of the month) and YYYY(year)
    Select ename,job,date_format(hiredate,' %a %D %b %Y') from emp2019274072 where deptno=20;

    MYSQL数据库SQL语句练习实验 EXERCISES 4 DATES_第2张图片

     

  3. Which employees were hired in April?
    Select ename, hiredate from emp2019274072 where data_format(hiredata,’%m’)=’04’;
    

    MYSQL数据库SQL语句练习实验 EXERCISES 4 DATES_第3张图片

     

  4. Which employees were hired on a Tuesday?
    Select ename,hiredate, date_format(hiredate,'%a') from emp2019274072 where date_format(hiredate,'%a')='Tue';

    MYSQL数据库SQL语句练习实验 EXERCISES 4 DATES_第4张图片

     

  5. Are there any employees who have worked more than 30 years for the company?
    select ename,timestampdiff(year,hiredate,now()) as workmonth from emp2019274072 where timestampdiff(year,hiredate,now())>30;

    MYSQL数据库SQL语句练习实验 EXERCISES 4 DATES_第5张图片

     

你可能感兴趣的:(数据库sql,sql,数据库,mysql)