2011-09-10 132 views
0

我做错了什么?已下订单的订单

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> 

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  SALESMAN 20-FEB-81 
WARD  SALESMAN 22-FEB-81 

SQL> 
+2

见你最后一个问题http://stackoverflow.com/questions/7373117/asending-order-for-hiredate和阅读sql语法并注意命令的顺序 – Mark

+2

您提出的问题太多,这些问题都是简单的语法错误。 Oracle文档是全面的,在线和免费的。在发布更多此类问题之前,请阅读它。在此处查找:http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/toc.htm – APC

回答

1

顺序排在最后(也有“奥得”而不是“命令”)

select ename, job, hiredate 
from emp where hiredate between '20-FEB-81' AND '01-MAY-81' 
order by hiredate asc 

上升是默认所以,除非你想下降是不是需要它但对可读性有好处

0
select ename, job, hiredate from emp where hiredate between '20-FEB-81' AND '01 MAY-81' order by hiredate acs 
2
  1. ORDER BY条款而来的WHERE条款
  2. ORDER BY条款是你不把它应用到列在SELECT列表单独clause--之后。
  3. 语法ORDER BY column_name [ASC|DESC]

所以,你想要的东西像

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