我有点问题。我需要在值之后对多个列进行排序,还要重新排列具有最高值的行。如果我举个例子,那就容易多了。
我的表:
name team erg1 erg2 erg3 erg4 erg5
Mike Blue 56 70 23 7 0
Dave Red 20 35 89 23 31
彼得格林5 90 23 0 0我需要的结果是这样的:
name team erg1 erg2 erg3 erg4 erg5
Peter Green 90 23 5 0 0
Dave Red 89 35 31 23 20
Mike Blue 70 56 23 7 0
在排序之前它的价值所在的女巫专栏并不重要。 有人理解我需要什么或知道如何做到这一点?
答案 0 :(得分:1)
您需要更新行中的值。以下内容非常冗长且重复,但它应该可行。
Update myTable set
erg1 = case when erg1 > erg2 and erg1 > erg3 and erg1 > erg4
and erg1 > erg5 then erg1
when erg2 > erg1 and erg2 > erg3 and erg2 > erg4
and erg1 > ergthen erg2
when erg3 > erg1 and erg3 > erg2 and erg3 > erg4
and erg3 > erg5 then erg3
when erg4 > erg1 and erg4 > erg2 and erg4 > erg3
and erg4 > erg5 then erg4 else erg5 end,
erg2 = case when erg1 < erg2 and erg1 > erg3 and erg1 > erg4
and erg1 > erg5 then erg1
when erg2 < erg1 and erg2 > erg3 and erg2 > erg4
and erg1 > erg5 then erg2
when erg3 < erg1 and erg3 > erg2 and erg3 > erg4
and erg3 > erg5 then erg3
when erg4 < erg1 and erg4 > erg2 and erg4 > erg3
and erg4 > erg5 then erg4 else erg5 end,
erg3 = case when erg1 < erg2 and erg1 < erg3 and erg1 > erg4
and erg1 > erg5 then erg1
when erg2 < erg1 and erg2 < erg3 and erg2 > erg4
and erg1 > erg5 then erg2
when erg3 < erg1 and erg3 < erg2 and erg3 > erg4
and erg3 > erg5 then erg3
when erg4 < erg1 and erg4 < erg2 and erg4 > erg3
and erg4 > erg5 then erg4 else erg5 end,
erg4 = case when erg1 < erg2 and erg1 < erg3 and erg1 < erg4
and erg1 > erg5 then erg1
when erg2 < erg1 and erg2 < erg3 and erg2 < erg4
and erg1 > erg5 then erg2
when erg3 < erg1 and erg3 < erg2 and erg3 < erg4
and erg3 > erg5 then erg3
when erg4 < erg1 and erg4 < erg2 and erg4 < erg3
and erg4 > erg5 then erg4 else erg5 end,
erg5 = case when erg1 < erg2 and erg1 < erg3 and erg1 < erg4
and erg1 < erg5 then erg1
when erg2 < erg1 and erg2 < erg3 and erg2 < erg4
and erg1 < erg5 then erg2
when erg3 < erg1 and erg3 < erg2 and erg3 < erg4
and erg3 < erg5 then erg3
when erg4 < erg1 and erg4 < erg2 and erg4 < erg3
and erg4 < erg5 then erg4 else erg5 end
答案 1 :(得分:0)
所以我添加了另一半列,现在它无法正常工作。现在它将每列设置为最高值。这是编辑过的代码:
UPDATE temp SET
erg1 = case when erg1 > erg2 and erg1 > erg3 and erg1 > erg4
and erg1 > erg5 and erg1 > erg6 and erg1 > erg7
and erg1 > erg8 and erg1 > erg9 and erg1 > erg10
then erg1
when erg2 > erg1 and erg2 > erg3 and erg2 > erg4
and erg2 > erg5 and erg2 > erg6 and erg2 > erg7
and erg2 > erg8 and erg2 > erg9 and erg2 >erg10
then erg2
when erg3 > erg1 and erg3 > erg2 and erg3 > erg4
and erg3 > erg5 and erg3 > erg6 and erg3 > erg7
and erg3 > erg8 and erg3 > erg9 and erg3 >erg10
then erg3
when erg4 > erg1 and erg4 > erg2 and erg4 > erg3
and erg4 > erg5 and erg4 > erg6 and erg4 > erg7
and erg4 > erg8 and erg4 > erg9 and erg4 >erg10
then erg4
when erg5 > erg1 and erg5 > erg2 and erg5 > erg3
and erg5 > erg4 and erg5 > erg6 and erg5 > erg7
and erg5 > erg8 and erg3 > erg9 and erg3 >erg10
then erg5
when erg6 > erg1 and erg6 > erg2 and erg6 > erg3
and erg6 > erg4 and erg6 > erg5 and erg6 > erg7
and erg6 > erg8 and erg6 > erg9 and erg6 >erg10
then erg6
when erg7 > erg1 and erg7 > erg2 and erg7 > erg3
and erg7 > erg4 and erg7 > erg5 and erg7 > erg6
and erg7 > erg8 and erg7 > erg9 and erg7 >erg10
then erg7
when erg8 > erg1 and erg8 > erg2 and erg8 > erg3
and erg8 > erg4 and erg8 > erg5 and erg8 > erg6
and erg8 > erg7 and erg8 > erg9 and erg8 >erg10
then erg8
when erg9 > erg1 and erg9 > erg2 and erg9 > erg3
and erg9 > erg4 and erg9 > erg5 and erg9 > erg6
and erg9 > erg7 and erg9 > erg8 and erg9 >erg10
then erg9 else erg10 end,
erg2 = case when erg1 > erg2 and erg1 > erg3 and erg1 > erg4
and erg1 > erg5 and erg1 > erg6 and erg1 > erg7
and erg1 > erg8 and erg1 > erg9 and erg1 > erg10
then erg1
when erg2 > erg1 and erg2 > erg3 and erg2 > erg4
and erg2 > erg5 and erg2 > erg6 and erg2 > erg7
and erg2 > erg8 and erg2 > erg9 and erg2 >erg10
then erg2
when erg3 > erg1 and erg3 > erg2 and erg3 > erg4
and erg3 > erg5 and erg3 > erg6 and erg3 > erg7
and erg3 > erg8 and erg3 > erg9 and erg3 >erg10
then erg3
when erg4 > erg1 and erg4 > erg2 and erg4 > erg3
and erg4 > erg5 and erg4 > erg6 and erg4 > erg7
and erg4 > erg8 and erg4 > erg9 and erg4 >erg10
then erg4
when erg5 > erg1 and erg5 > erg2 and erg5 > erg3
and erg5 > erg4 and erg5 > erg6 and erg5 > erg7
and erg5 > erg8 and erg3 > erg9 and erg3 >erg10
then erg5
when erg6 > erg1 and erg6 > erg2 and erg6 > erg3
and erg6 > erg4 and erg6 > erg5 and erg6 > erg7
and erg6 > erg8 and erg6 > erg9 and erg6 >erg10
then erg6
when erg7 > erg1 and erg7 > erg2 and erg7 > erg3
and erg7 > erg4 and erg7 > erg5 and erg7 > erg6
and erg7 > erg8 and erg7 > erg9 and erg7 >erg10
then erg7
when erg8 > erg1 and erg8 > erg2 and erg8 > erg3
and erg8 > erg4 and erg8 > erg5 and erg8 > erg6
and erg8 > erg7 and erg8 > erg9 and erg8 >erg10
then erg8
when erg9 > erg1 and erg9 > erg2 and erg9 > erg3
and erg9 > erg4 and erg9 > erg5 and erg9 > erg6
and erg9 > erg7 and erg9 > erg8 and erg9 >erg10
then erg9 else erg10 end,
erg3 = case when erg1 > erg2 and erg1 > erg3 and erg1 > erg4
and erg1 > erg5 and erg1 > erg6 and erg1 > erg7
and erg1 > erg8 and erg1 > erg9 and erg1 > erg10
then erg1
when erg2 > erg1 and erg2 > erg3 and erg2 > erg4
and erg2 > erg5 and erg2 > erg6 and erg2 > erg7
and erg2 > erg8 and erg2 > erg9 and erg2 >erg10
then erg2
when erg3 > erg1 and erg3 > erg2 and erg3 > erg4
and erg3 > erg5 and erg3 > erg6 and erg3 > erg7
and erg3 > erg8 and erg3 > erg9 and erg3 >erg10
then erg3
when erg4 > erg1 and erg4 > erg2 and erg4 > erg3
and erg4 > erg5 and erg4 > erg6 and erg4 > erg7
and erg4 > erg8 and erg4 > erg9 and erg4 >erg10
then erg4
when erg5 > erg1 and erg5 > erg2 and erg5 > erg3
and erg5 > erg4 and erg5 > erg6 and erg5 > erg7
and erg5 > erg8 and erg3 > erg9 and erg3 >erg10
then erg5
when erg6 > erg1 and erg6 > erg2 and erg6 > erg3
and erg6 > erg4 and erg6 > erg5 and erg6 > erg7
and erg6 > erg8 and erg6 > erg9 and erg6 >erg10
then erg6
when erg7 > erg1 and erg7 > erg2 and erg7 > erg3
and erg7 > erg4 and erg7 > erg5 and erg7 > erg6
and erg7 > erg8 and erg7 > erg9 and erg7 >erg10
then erg7
when erg8 > erg1 and erg8 > erg2 and erg8 > erg3
and erg8 > erg4 and erg8 > erg5 and erg8 > erg6
and erg8 > erg7 and erg8 > erg9 and erg8 >erg10
then erg8
when erg9 > erg1 and erg9 > erg2 and erg9 > erg3
and erg9 > erg4 and erg9 > erg5 and erg9 > erg6
and erg9 > erg7 and erg9 > erg8 and erg9 >erg10
then erg9 else erg10 end,
erg4 = case when erg1 > erg2 and erg1 > erg3 and erg1 > erg4
and erg1 > erg5 and erg1 > erg6 and erg1 > erg7
and erg1 > erg8 and erg1 > erg9 and erg1 > erg10
then erg1
when erg2 > erg1 and erg2 > erg3 and erg2 > erg4
and erg2 > erg5 and erg2 > erg6 and erg2 > erg7
and erg2 > erg8 and erg2 > erg9 and erg2 >erg10
then erg2
when erg3 > erg1 and erg3 > erg2 and erg3 > erg4
and erg3 > erg5 and erg3 > erg6 and erg3 > erg7
and erg3 > erg8 and erg3 > erg9 and erg3 >erg10
then erg3
when erg4 > erg1 and erg4 > erg2 and erg4 > erg3
and erg4 > erg5 and erg4 > erg6 and erg4 > erg7
and erg4 > erg8 and erg4 > erg9 and erg4 >erg10
then erg4
when erg5 > erg1 and erg5 > erg2 and erg5 > erg3
and erg5 > erg4 and erg5 > erg6 and erg5 > erg7
and erg5 > erg8 and erg3 > erg9 and erg3 >erg10
then erg5
when erg6 > erg1 and erg6 > erg2 and erg6 > erg3
and erg6 > erg4 and erg6 > erg5 and erg6 > erg7
and erg6 > erg8 and erg6 > erg9 and erg6 >erg10
then erg6
when erg7 > erg1 and erg7 > erg2 and erg7 > erg3
and erg7 > erg4 and erg7 > erg5 and erg7 > erg6
and erg7 > erg8 and erg7 > erg9 and erg7 >erg10
then erg7
when erg8 > erg1 and erg8 > erg2 and erg8 > erg3
and erg8 > erg4 and erg8 > erg5 and erg8 > erg6
and erg8 > erg7 and erg8 > erg9 and erg8 >erg10
then erg8
when erg9 > erg1 and erg9 > erg2 and erg9 > erg3
and erg9 > erg4 and erg9 > erg5 and erg9 > erg6
and erg9 > erg7 and erg9 > erg8 and erg9 >erg10
then erg9 else erg10 end,
erg5 = case when erg1 > erg2 and erg1 > erg3 and erg1 > erg4
and erg1 > erg5 and erg1 > erg6 and erg1 > erg7
and erg1 > erg8 and erg1 > erg9 and erg1 > erg10
then erg1
when erg2 > erg1 and erg2 > erg3 and erg2 > erg4
and erg2 > erg5 and erg2 > erg6 and erg2 > erg7
and erg2 > erg8 and erg2 > erg9 and erg2 >erg10
then erg2
when erg3 > erg1 and erg3 > erg2 and erg3 > erg4
and erg3 > erg5 and erg3 > erg6 and erg3 > erg7
and erg3 > erg8 and erg3 > erg9 and erg3 >erg10
then erg3
when erg4 > erg1 and erg4 > erg2 and erg4 > erg3
and erg4 > erg5 and erg4 > erg6 and erg4 > erg7
and erg4 > erg8 and erg4 > erg9 and erg4 >erg10
then erg4
when erg5 > erg1 and erg5 > erg2 and erg5 > erg3
and erg5 > erg4 and erg5 > erg6 and erg5 > erg7
and erg5 > erg8 and erg3 > erg9 and erg3 >erg10
then erg5
when erg6 > erg1 and erg6 > erg2 and erg6 > erg3
and erg6 > erg4 and erg6 > erg5 and erg6 > erg7
and erg6 > erg8 and erg6 > erg9 and erg6 >erg10
then erg6
when erg7 > erg1 and erg7 > erg2 and erg7 > erg3
and erg7 > erg4 and erg7 > erg5 and erg7 > erg6
and erg7 > erg8 and erg7 > erg9 and erg7 >erg10
then erg7
when erg8 > erg1 and erg8 > erg2 and erg8 > erg3
and erg8 > erg4 and erg8 > erg5 and erg8 > erg6
and erg8 > erg7 and erg8 > erg9 and erg8 >erg10
then erg8
when erg9 > erg1 and erg9 > erg2 and erg9 > erg3
and erg9 > erg4 and erg9 > erg5 and erg9 > erg6
and erg9 > erg7 and erg9 > erg8 and erg9 >erg10
then erg9 else erg10 end,
erg6 = case when erg1 > erg2 and erg1 > erg3 and erg1 > erg4
and erg1 > erg5 and erg1 > erg6 and erg1 > erg7
and erg1 > erg8 and erg1 > erg9 and erg1 > erg10
then erg1
when erg2 > erg1 and erg2 > erg3 and erg2 > erg4
and erg2 > erg5 and erg2 > erg6 and erg2 > erg7
and erg2 > erg8 and erg2 > erg9 and erg2 >erg10
then erg2
when erg3 > erg1 and erg3 > erg2 and erg3 > erg4
and erg3 > erg5 and erg3 > erg6 and erg3 > erg7
and erg3 > erg8 and erg3 > erg9 and erg3 >erg10
then erg3
when erg4 > erg1 and erg4 > erg2 and erg4 > erg3
and erg4 > erg5 and erg4 > erg6 and erg4 > erg7
and erg4 > erg8 and erg4 > erg9 and erg4 >erg10
then erg4
when erg5 > erg1 and erg5 > erg2 and erg5 > erg3
and erg5 > erg4 and erg5 > erg6 and erg5 > erg7
and erg5 > erg8 and erg3 > erg9 and erg3 >erg10
then erg5
when erg6 > erg1 and erg6 > erg2 and erg6 > erg3
and erg6 > erg4 and erg6 > erg5 and erg6 > erg7
and erg6 > erg8 and erg6 > erg9 and erg6 >erg10
then erg6
when erg7 > erg1 and erg7 > erg2 and erg7 > erg3
and erg7 > erg4 and erg7 > erg5 and erg7 > erg6
and erg7 > erg8 and erg7 > erg9 and erg7 >erg10
then erg7
when erg8 > erg1 and erg8 > erg2 and erg8 > erg3
and erg8 > erg4 and erg8 > erg5 and erg8 > erg6
and erg8 > erg7 and erg8 > erg9 and erg8 >erg10
then erg8
when erg9 > erg1 and erg9 > erg2 and erg9 > erg3
and erg9 > erg4 and erg9 > erg5 and erg9 > erg6
and erg9 > erg7 and erg9 > erg8 and erg9 >erg10
then erg9 else erg10 end,
erg7 = case when erg1 > erg2 and erg1 > erg3 and erg1 > erg4
and erg1 > erg5 and erg1 > erg6 and erg1 > erg7
and erg1 > erg8 and erg1 > erg9 and erg1 > erg10
then erg1
when erg2 > erg1 and erg2 > erg3 and erg2 > erg4
and erg2 > erg5 and erg2 > erg6 and erg2 > erg7
and erg2 > erg8 and erg2 > erg9 and erg2 >erg10
then erg2
when erg3 > erg1 and erg3 > erg2 and erg3 > erg4
and erg3 > erg5 and erg3 > erg6 and erg3 > erg7
and erg3 > erg8 and erg3 > erg9 and erg3 >erg10
then erg3
when erg4 > erg1 and erg4 > erg2 and erg4 > erg3
and erg4 > erg5 and erg4 > erg6 and erg4 > erg7
and erg4 > erg8 and erg4 > erg9 and erg4 >erg10
then erg4
when erg5 > erg1 and erg5 > erg2 and erg5 > erg3
and erg5 > erg4 and erg5 > erg6 and erg5 > erg7
and erg5 > erg8 and erg3 > erg9 and erg3 >erg10
then erg5
when erg6 > erg1 and erg6 > erg2 and erg6 > erg3
and erg6 > erg4 and erg6 > erg5 and erg6 > erg7
and erg6 > erg8 and erg6 > erg9 and erg6 >erg10
then erg6
when erg7 > erg1 and erg7 > erg2 and erg7 > erg3
and erg7 > erg4 and erg7 > erg5 and erg7 > erg6
and erg7 > erg8 and erg7 > erg9 and erg7 >erg10
then erg7
when erg8 > erg1 and erg8 > erg2 and erg8 > erg3
and erg8 > erg4 and erg8 > erg5 and erg8 > erg6
and erg8 > erg7 and erg8 > erg9 and erg8 >erg10
then erg8
when erg9 > erg1 and erg9 > erg2 and erg9 > erg3
and erg9 > erg4 and erg9 > erg5 and erg9 > erg6
and erg9 > erg7 and erg9 > erg8 and erg9 >erg10
then erg9 else erg10 end,
erg8 = case when erg1 > erg2 and erg1 > erg3 and erg1 > erg4
and erg1 > erg5 and erg1 > erg6 and erg1 > erg7
and erg1 > erg8 and erg1 > erg9 and erg1 > erg10
then erg1
when erg2 > erg1 and erg2 > erg3 and erg2 > erg4
and erg2 > erg5 and erg2 > erg6 and erg2 > erg7
and erg2 > erg8 and erg2 > erg9 and erg2 >erg10
then erg2
when erg3 > erg1 and erg3 > erg2 and erg3 > erg4
and erg3 > erg5 and erg3 > erg6 and erg3 > erg7
and erg3 > erg8 and erg3 > erg9 and erg3 >erg10
then erg3
when erg4 > erg1 and erg4 > erg2 and erg4 > erg3
and erg4 > erg5 and erg4 > erg6 and erg4 > erg7
and erg4 > erg8 and erg4 > erg9 and erg4 >erg10
then erg4
when erg5 > erg1 and erg5 > erg2 and erg5 > erg3
and erg5 > erg4 and erg5 > erg6 and erg5 > erg7
and erg5 > erg8 and erg3 > erg9 and erg3 >erg10
then erg5
when erg6 > erg1 and erg6 > erg2 and erg6 > erg3
and erg6 > erg4 and erg6 > erg5 and erg6 > erg7
and erg6 > erg8 and erg6 > erg9 and erg6 >erg10
then erg6
when erg7 > erg1 and erg7 > erg2 and erg7 > erg3
and erg7 > erg4 and erg7 > erg5 and erg7 > erg6
and erg7 > erg8 and erg7 > erg9 and erg7 >erg10
then erg7
when erg8 > erg1 and erg8 > erg2 and erg8 > erg3
and erg8 > erg4 and erg8 > erg5 and erg8 > erg6
and erg8 > erg7 and erg8 > erg9 and erg8 >erg10
then erg8
when erg9 > erg1 and erg9 > erg2 and erg9 > erg3
and erg9 > erg4 and erg9 > erg5 and erg9 > erg6
and erg9 > erg7 and erg9 > erg8 and erg9 >erg10
then erg9 else erg10 end,
erg9 = case when erg1 > erg2 and erg1 > erg3 and erg1 > erg4
and erg1 > erg5 and erg1 > erg6 and erg1 > erg7
and erg1 > erg8 and erg1 > erg9 and erg1 > erg10
then erg1
when erg2 > erg1 and erg2 > erg3 and erg2 > erg4
and erg2 > erg5 and erg2 > erg6 and erg2 > erg7
and erg2 > erg8 and erg2 > erg9 and erg2 >erg10
then erg2
when erg3 > erg1 and erg3 > erg2 and erg3 > erg4
and erg3 > erg5 and erg3 > erg6 and erg3 > erg7
and erg3 > erg8 and erg3 > erg9 and erg3 >erg10
then erg3
when erg4 > erg1 and erg4 > erg2 and erg4 > erg3
and erg4 > erg5 and erg4 > erg6 and erg4 > erg7
and erg4 > erg8 and erg4 > erg9 and erg4 >erg10
then erg4
when erg5 > erg1 and erg5 > erg2 and erg5 > erg3
and erg5 > erg4 and erg5 > erg6 and erg5 > erg7
and erg5 > erg8 and erg3 > erg9 and erg3 >erg10
then erg5
when erg6 > erg1 and erg6 > erg2 and erg6 > erg3
and erg6 > erg4 and erg6 > erg5 and erg6 > erg7
and erg6 > erg8 and erg6 > erg9 and erg6 >erg10
then erg6
when erg7 > erg1 and erg7 > erg2 and erg7 > erg3
and erg7 > erg4 and erg7 > erg5 and erg7 > erg6
and erg7 > erg8 and erg7 > erg9 and erg7 >erg10
then erg7
when erg8 > erg1 and erg8 > erg2 and erg8 > erg3
and erg8 > erg4 and erg8 > erg5 and erg8 > erg6
and erg8 > erg7 and erg8 > erg9 and erg8 >erg10
then erg8
when erg9 > erg1 and erg9 > erg2 and erg9 > erg3
and erg9 > erg4 and erg9 > erg5 and erg9 > erg6
and erg9 > erg7 and erg9 > erg8 and erg9 >erg10
then erg9 else erg10 end,
erg10 = case when erg1 > erg2 and erg1 > erg3 and erg1 > erg4
and erg1 > erg5 and erg1 > erg6 and erg1 > erg7
and erg1 > erg8 and erg1 > erg9 and erg1 > erg10
then erg1
when erg2 > erg1 and erg2 > erg3 and erg2 > erg4
and erg2 > erg5 and erg2 > erg6 and erg2 > erg7
and erg2 > erg8 and erg2 > erg9 and erg2 >erg10
then erg2
when erg3 > erg1 and erg3 > erg2 and erg3 > erg4
and erg3 > erg5 and erg3 > erg6 and erg3 > erg7
and erg3 > erg8 and erg3 > erg9 and erg3 >erg10
then erg3
when erg4 > erg1 and erg4 > erg2 and erg4 > erg3
and erg4 > erg5 and erg4 > erg6 and erg4 > erg7
and erg4 > erg8 and erg4 > erg9 and erg4 >erg10
then erg4
when erg5 > erg1 and erg5 > erg2 and erg5 > erg3
and erg5 > erg4 and erg5 > erg6 and erg5 > erg7
and erg5 > erg8 and erg3 > erg9 and erg3 >erg10
then erg5
when erg6 > erg1 and erg6 > erg2 and erg6 > erg3
and erg6 > erg4 and erg6 > erg5 and erg6 > erg7
and erg6 > erg8 and erg6 > erg9 and erg6 >erg10
then erg6
when erg7 > erg1 and erg7 > erg2 and erg7 > erg3
and erg7 > erg4 and erg7 > erg5 and erg7 > erg6
and erg7 > erg8 and erg7 > erg9 and erg7 >erg10
then erg7
when erg8 > erg1 and erg8 > erg2 and erg8 > erg3
and erg8 > erg4 and erg8 > erg5 and erg8 > erg6
and erg8 > erg7 and erg8 > erg9 and erg8 >erg10
then erg8
when erg9 > erg1 and erg9 > erg2 and erg9 > erg3
and erg9 > erg4 and erg9 > erg5 and erg9 > erg6
and erg9 > erg7 and erg9 > erg8 and erg9 >erg10
then erg9 else erg10 end