租赁日期的升序

时间:2011-09-10 16:44:17

标签: sql oracle sqlplus

我做错了什么?

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>

3 个答案:

答案 0 :(得分:2)

  1. ORDER BY子句位于WHERE子句
  2. 之后
  3. ORDER BY子句是一个单独的子句 - 您不会将其应用于SELECT列表中的列。
  4. 语法为ORDER BY column_name [ASC|DESC]
  5. 所以你想要像

    这样的东西
    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
    

答案 1 :(得分:1)

订单来到最后(你也有“oder”而非“订单”)

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

升序是默认值,因此除非您想要降序,否则不需要它,但它有利于可读性

答案 2 :(得分:0)

select ename, job, hiredate  from emp where hiredate between '20-FEB-81' AND '01 MAY-81' order by hiredate acs
相关问题