日期排序问题,恳请各位大哥帮忙 现在数据库中譬如说有两个字段用户姓名(yhxm)、最后修改时间(zhxgsj),但是最后修改时间有的是null,有的不是,我现在想要的结果是,按照最后修改时间排序,时间离今天越近的在最上面,然后是离今天越远的,最后是为null的,如果按照最后修改时间asc、desc都不行,大家有没有什么比较好的办法 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ORDER BY zhxgsj DESC nulls last order by zhxgsj desc nulls last select * from your_table order by zhxgsj desc nulls last; DESC NULLS LAST 正解 --null默认就是按照最大的处理,为什么要加nulls last?Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 Connected as SYSSQL> select * from scott.a; COL1 COL2 COL4----- ----- ------------------------------ 1 2 2 1 2 2 1 2 2 1 2 2 1 2 22 1 2 22 1 2 227 rows selectedSQL> desc a;Object a does not exist.SQL> desc scott.a;Name Type Nullable Default Comments ---- --------- -------- ------- -------- COL1 NUMBER(4) Y COL2 NUMBER(4) Y COL4 CHAR(30) Y SQL> insert into scott.a values(1,3,null);1 row insertedSQL> insert into scott.a values(1,4,null);1 row insertedSQL> insert into scott.a values(1,6,null);1 row insertedSQL> insert into scott.a values(7,6,null);1 row insertedSQL> commit;Commit completeSQL> select * from scott.a; COL1 COL2 COL4----- ----- ------------------------------ 1 2 2 1 2 2 1 2 2 1 2 2 1 3 1 4 1 6 7 6 1 2 22 1 2 22 1 2 2211 rows selectedSQL> select * from scott.a order by col4 desc; COL1 COL2 COL4----- ----- ------------------------------ 1 4 7 6 1 6 1 3 1 2 22 1 2 22 1 2 22 1 2 2 1 2 2 1 2 2 1 2 211 rows selectedSQL> select * from scott.a order by col4 asc; COL1 COL2 COL4----- ----- ------------------------------ 1 2 2 1 2 2 1 2 2 1 2 2 1 2 22 1 2 22 1 2 22 7 6 1 6 1 3 1 4 11 rows selectedSQL> 重发,加分,100分求排序问题 急救!!ORACLE从8I升级为10I后原来使用DP2000开发的FORM无法编译。 在hibernate映射Oracle表的时候出现错误,求助 我在erp里执行一个查询,可是在v$sql里监控不到语句 请问该存储过程用oracle怎么写啊!50 为什么我的表不自动排序? 插入的时候自动累加的问题! 触发器没有反映,不知道哪里出问题了! :( 游标没关闭会导致数据库内存泄露吗?数据库服务器每天掉100内存,晕! 控制文件的多路复用 在Enterprise Manager Console如何创建表空间? Oracle 对于blob型字段的查询疑问。
Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
Connected as SYS
SQL> select * from scott.a; COL1 COL2 COL4
----- ----- ------------------------------
1 2 2
1 2 2
1 2 2
1 2 2
1 2 22
1 2 22
1 2 227 rows selectedSQL> desc a;
Object a does not exist.SQL> desc scott.a;
Name Type Nullable Default Comments
---- --------- -------- ------- --------
COL1 NUMBER(4) Y
COL2 NUMBER(4) Y
COL4 CHAR(30) Y SQL> insert into scott.a values(1,3,null);1 row insertedSQL> insert into scott.a values(1,4,null);1 row insertedSQL> insert into scott.a values(1,6,null);1 row insertedSQL> insert into scott.a values(7,6,null);1 row insertedSQL> commit;Commit completeSQL> select * from scott.a; COL1 COL2 COL4
----- ----- ------------------------------
1 2 2
1 2 2
1 2 2
1 2 2
1 3
1 4
1 6
7 6
1 2 22
1 2 22
1 2 2211 rows selectedSQL> select * from scott.a order by col4 desc; COL1 COL2 COL4
----- ----- ------------------------------
1 4
7 6
1 6
1 3
1 2 22
1 2 22
1 2 22
1 2 2
1 2 2
1 2 2
1 2 211 rows selectedSQL> select * from scott.a order by col4 asc; COL1 COL2 COL4
----- ----- ------------------------------
1 2 2
1 2 2
1 2 2
1 2 2
1 2 22
1 2 22
1 2 22
7 6
1 6
1 3
1 4 11 rows selectedSQL>