我有一个问题,即写一份SELECT语句,以获取1998年7月至1999年12月期间雇用的雇员名单。该列表必须包含员工ID,姓氏和名字以及月薪 - 假设该表包含年薪,员工每年可获得12个工资。
我写了这个,但不起作用:
SELECT FIRST_NAME, LAST_NAME, EMPLOYEE_ID, SALARY/12 as MONTHLY_SALARY
FROM HR.EMPLOYEES
WHERE HIRE_DATE BETWEEN JULY-1998 AND DECEMBER-1999 ;
答案 0 :(得分:0)
可能是您的日期格式错误(对于mysql)
SELECT FIRST_NAME, LAST_NAME, EMPLOYEE_ID, SALARY/12 as MONTHLY_SALARY
FROM HR.EMPLOYEES
WHERE HIRE_DATE BETWEEN STR_TO_DATE('07-01-1998, '%m-%d-%Y)
AND STR_TO_DATE('12-31-1999, '%m-%d-%Y) D ;
对于sqlserver
SELECT FIRST_NAME, LAST_NAME, EMPLOYEE_ID, SALARY/12 as MONTHLY_SALARY
FROM HR.EMPLOYEES
WHERE HIRE_DATE BETWEEN Cast('07-01-1998'as datetime)
AND Cast('12-31-1999' as datetime) ;
对于ORACLE
SELECT FIRST_NAME, LAST_NAME, EMPLOYEE_ID, SALARY/12 as MONTHLY_SALARY
FROM HR.EMPLOYEES
WHERE HIRE_DATE BETWEEN TO_DATE('07-01-1998' , 'MM-DD-YYYY')
AND TO_DATE('12-31-1999' , 'MM-DD-YYYY') ;