Asending order for hiredate
What am I doing wrong?
SQL> select ename, job, oder by (ascending order)hiredate from emp where hiredate between '20-FEB-81' AND '01-MAY-81';
select ename, job, oder by (ascending order)hiredate from emp where hiredate between '20-FEB-81' AND '01-MAY-81'
*
ERROR at line 1:
ORA-00923: FROM keyword not found where expected
SQL>
Table
SQL> select ename, job, hiredate from emp where hiredate between '20-FEB-81' AND '01 MAY-81';
ENAME JOB HIREDATE
---------- --------- ---------
BLAKE MANAGER 01-MAY-81
JONES MANAGER 02-APR-81
ALLEN 开发者_JAVA技巧 SALESMAN 20-FEB-81
WARD SALESMAN 22-FEB-81
SQL>
- The
ORDER BY
clause comes after theWHERE
clause - The
ORDER BY
clause is a separate clause-- you don't apply it to the column in theSELECT
list. - The syntax is
ORDER BY column_name [ASC|DESC]
So you'd want something like
SQL> select ename, job, hiredate
2 from emp
3 where hiredate between to_date( '20-FEB-81', 'DD-MON-RR' ) and
4 to_date( '01-MAY-81', 'DD-MON-RR' )
5 order by hiredate asc;
ENAME JOB HIREDATE
---------- --------- ----------
ALLEN SALESMAN 1981-02-20
WARD SALESMAN 1981-02-22
JONES MANAGER 1981-04-02
BLAKE MANAGER 1981-05-01
order comes last (you also had "oder" not "order")
select ename, job, hiredate
from emp where hiredate between '20-FEB-81' AND '01-MAY-81'
order by hiredate asc
ascending is the default so unless you want descending it is not needed but it is good for readability
select ename, job, hiredate from emp where hiredate between '20-FEB-81' AND '01 MAY-81' order by hiredate acs
精彩评论