summoner 发表于 2007-5-15 12:46

怎样写这样的排序语句

数据库中<BR>A    B    C    D<BR>1    1    1    2<BR>2    2         3<BR>3    3    2    1<BR>......<BR>页面上有一列的值:C列的值为null时显示B列相应的值,C列不为null时显示D列的值,<BR>显示在页面上的结果要这样<BR>A    X    C<BR>1    2    1<BR>2    2        <BR>3    1    2<BR>......    <BR>现在要求根据显示出来的这一列的值排序,怎么写这条排序语句?<BR><BR>

bygg 发表于 2007-5-16 13:32

<P>create  PROCEDURE selData<BR>AS</P>
<P>create table #testX<BR>(  <BR>   ta int,<BR>   tx int,<BR>   tc int<BR>)<BR>begin<BR>insert into #testX select A,(case C when isnull(C,0) then D else B end) as X ,C from tbABCD<BR>select * from #testX<BR>drop table #testX<BR>end<BR><BR>---------------------<BR>exec selData</P>

summoner 发表于 2007-5-16 14:17

Error<BR>[row:9,col:29] ORA-00904: "ISNULL": invalid identifier

summoner 发表于 2007-5-16 14:19

不过用这个就行了<BR>case C when C then B else D end<BR>

bygg 发表于 2007-5-16 15:23

不是吧.我测试时都没有错的呢..

心中有剑 发表于 2007-5-18 14:02

A    B    C    D<BR>1    1    1    2<BR>2    2         3<BR>3    3    2    1<BR><BR><BR>select A, DECODE(C,NULL,B,D) AS X ,C FROM tableTest order by A<BR>这样就应该可以了吧

dwt 发表于 2007-10-17 11:07

select a, nvl2(c,d,b) as x , c from aaa;<br>这个最好<br>

liuye 发表于 2007-10-23 16:58

select a,nvl2(c,d,b) x,c from aaa;

页: [1]

编程论坛