Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 如何按降序排列各行?_Algorithm_Oracle_Plsql - Fatal编程技术网

Algorithm 如何按降序排列各行?

Algorithm 如何按降序排列各行?,algorithm,oracle,plsql,Algorithm,Oracle,Plsql,我有一张如下所示的桌子: Name LastName tPoints aPoints sPoints gPoints type John Johnny 15 14 13 10 1 Joe P. 12 11 26 10 1 Matt Q. 11 26 37 44 2 Sorine P. 55 9 8

我有一张如下所示的桌子:

Name LastName tPoints aPoints sPoints gPoints type
John   Johnny   15      14     13      10       1
Joe     P.      12      11     26      10       1
Matt    Q.      11      26     37      44       2
Sorine  P.      55      9      8        7       2
Ali     Ahmed   30      44     88      65       2 
...     ...     ..      ..      ..     ..       3            
                                                3
我想根据
TYPE

注意:
我不能在oracle中使用order by,因为它只对1行和其他行进行排序
根据第一行进行排序

我不想将表拆分为单独的表,然后对其进行排序,然后将其更新回原始表

因此,输出将如下所示,对于
t点
-我需要显示所有

15  - John Johnny
12  - Joe P. 
对于
apoint

44  - Ali Ahmed
26  - Matt Q.
 9  - Sorine P.
等等

简而言之,如果type=1,则按降序对t点进行排序;如果type=2,则对apoint进行排序;如果type=3,则对spoint进行排序,依此类推。

有什么有效的方法来解决这个问题


关于,

为了简单起见,此示例仅包括两种类型。根据需要添加尽可能多的类型

SQL> with t1(Name1, LastName, tPoints, aPoints, sPoints, gPoints, type1) as(
  2  select 'John'  ,  'Johnny',  15,  14,  13,  10,   1  from dual union all
  3  select 'Joe'   ,  'P.'    ,  12,  11,  26,  10,   1  from dual union all
  4  select 'Matt'  ,  'Q.'    ,  11,  26,  37,  44,   2  from dual union all
  5  select 'Sorine',  'P.'    ,  55,  9 ,  8 ,  7,    2  from dual union all
  6  select 'Ali'   ,  'Ahmed' ,  30,  44,  88,  65,   2   from dual
  7  )
  8  select type1
  9       , tpoints
 10       , apoints
 11       , name1
 12       , Lastname
 13    from t1
 14   order by case when type1=1 then tpoints else type1 end desc,
 15            case when type1=2 then apoints else type1 end desc;

     TYPE1    TPOINTS    APOINTS NAME1  LASTNAME
---------- ---------- ---------- ------ --------
         1         15         14 John   Johnny
         1         12         11 Joe    P.
         2         30         44 Ali    Ahmed
         2         11         26 Matt   Q.
         2         55          9 Sorine P.

为了简单起见,此示例仅包括两种类型。根据需要添加尽可能多的类型

SQL> with t1(Name1, LastName, tPoints, aPoints, sPoints, gPoints, type1) as(
  2  select 'John'  ,  'Johnny',  15,  14,  13,  10,   1  from dual union all
  3  select 'Joe'   ,  'P.'    ,  12,  11,  26,  10,   1  from dual union all
  4  select 'Matt'  ,  'Q.'    ,  11,  26,  37,  44,   2  from dual union all
  5  select 'Sorine',  'P.'    ,  55,  9 ,  8 ,  7,    2  from dual union all
  6  select 'Ali'   ,  'Ahmed' ,  30,  44,  88,  65,   2   from dual
  7  )
  8  select type1
  9       , tpoints
 10       , apoints
 11       , name1
 12       , Lastname
 13    from t1
 14   order by case when type1=1 then tpoints else type1 end desc,
 15            case when type1=2 then apoints else type1 end desc;

     TYPE1    TPOINTS    APOINTS NAME1  LASTNAME
---------- ---------- ---------- ------ --------
         1         15         14 John   Johnny
         1         12         11 Joe    P.
         2         30         44 Ali    Ahmed
         2         11         26 Matt   Q.
         2         55          9 Sorine P.


行还是列?您能给我们一个具体的例子吗?只需将其导出到excel,然后按您的意愿重新排列即可。@nathanhayfield这是一个存储过程,不可能,但是thanks@Will请再次查看该问题,我已根据类型修改了它的显示
TYPE
订购过程中
TYPE
的具体参与程度?行还是列?您能给我们一个具体的例子吗?只需将其导出到excel,然后按您的意愿重新排列即可。@nathanhayfield这是一个存储过程,不可能,但是thanks@Will请再次查看该问题,我已根据类型修改了它的显示
TYPE
订购过程中
TYPE
的具体参与程度?这可能会起作用。只是想知道,如果我想使用上面的方法,但是
insert-Into-Select
插入到一个新表中,这样我就可以以我想要的方式显示-?@user1683987否,您将不会对
insert-Into-table-Select
有任何问题。此外,在一个表中插入一组有序的数据是没有任何意义的,我需要显示每一个单独排序的类型,所以我想这是我唯一的选择。除非你知道另一种显示方式-@user1683987对不起,但我不懂。您所说的显示每种单独排序的类型是什么意思?您希望结果数据集的显示方式如何?我希望在每种类型之间留出空格,并使用类似于
具有最高tPoints的人的标题,然后添加新行,然后显示与该类型关联的数据,等等。对于其他类型,这可能可行。只是想知道,如果我想使用上面的方法,但是
insert-Into-Select
插入到一个新表中,这样我就可以以我想要的方式显示-?@user1683987否,您将不会对
insert-Into-table-Select
有任何问题。此外,在一个表中插入一组有序的数据是没有任何意义的,我需要显示每一个单独排序的类型,所以我想这是我唯一的选择。除非你知道另一种显示方式-@user1683987对不起,但我不懂。您所说的显示每种单独排序的类型是什么意思?您希望结果数据集的显示方式如何?我希望在每种类型之间留出空格,并使用类似于
最高tPoints的人的标题,然后添加新行,然后显示与该类型关联的数据,对于其他类型,依此类推