2013-03-23 30 views
0

我有一個關於查詢的問題。假設我有這樣的表結構。對列進行排序並將結果設置爲MySql中的另一列

TABLE_A 
Id - Standing - Point 
1  null  8 
2  null  9 
3  null  12 
4  null  11 
5  null  4 

當我排序列點此表(SELECT * FROM TABLE_A ORDER BY DESC點)根據排序結果,我想更新立柱進行更新。排序和這些值設置爲立柱,我希望有結果後是這樣的:

TABLE_A 
Id - Standing - Point 
1  4  8 
2  3  9 
3  1  12 
4  2  11 
5  5  4 

是否有可能做到這一點?如果是,如何?

在此先感謝...

+0

通常,您不應該存儲可以輕鬆從其他數據派生的數據。 – Strawberry 2013-03-23 12:16:54

回答

1

您可以用相當神祕的語法做到這一點:

update table_A 
    set standing = (select cnt 
        from (select count(*) as cnt 
          from table_a a2 
          where a2.point >= table_A.point 
         ) 
        ) 

使用嵌套選擇的僅僅是在MySQL所需的語法約定。

相關問題