日期:2014-05-17  浏览次数:21075 次

求sql大牛来帮忙!!!!!!
假设有这么个表:
htbh dzkje hkrq
001 500 2011-01-01
002 400 2011-06-05
001 600 2011-07-01
002 800 2010-12-12
我想要变成这样的结果,sql应该怎么写啊?
001 600 2011-07-01
001 500 2011-01-01
002 400 2011-06-05
002 800 2010-12-12

------解决方案--------------------
SQL code

--直接上代码不解释,不过看不出来你的 日期按照什么规矩排序,001的乱排呢。。
SQL> with t1 as(
  2  select '001' htbh, 500 dzkje, '2011-01-01'hkrq from dual union all
  3  select '002' htbh, 400 dzkje, '2011-06-05'hkrq from dual union all
  4  select '001' htbh, 600 dzkje, '2011-07-01'hkrq from dual union all
  5  select '002' htbh, 800 dzkje, '2010-12-12'hkrq from dual union all
  6  select '003' htbh, 900 dzkje, '2010-07-07'hkrq from dual union all
  7  select '001' htbh, 600 dzkje, '2010-08-09'hkrq from dual union all
  8  select '004' htbh, 200 dzkje, '2010-01-26'hkrq from dual union all
  9  select '003' htbh, 600 dzkje, '2010-12-12'hkrq from dual union all
 10  select '004' htbh, 900 dzkje, '2011-07-12'hkrq from dual)
 11  select htbh,dzkje,hkrq
 12    from t1
 13   order by htbh,hkrq desc;

HTB      DZKJE HKRQ
--- ---------- ----------
001        600 2011-07-01
001        500 2011-01-01
001        600 2010-08-09
002        400 2011-06-05
002        800 2010-12-12
003        600 2010-12-12
003        900 2010-07-07
004        900 2011-07-12
004        200 2010-01-26

已选择9行。

SQL>