0

i have a following PREFERENCE_SCORE table

ID(int) | SCORE(Double) | RANKING(int) |

I want to insert into database using the following code

String sql = "INSERT INTO PREFERENCE_SCORE_ ( ID, 
              SCORE,RANK) VALUES (?,?,?) ";
String query ="SELECT ID,FPIS,FNIS FROM db_housekeep";
ResultSet rsp = stats.executeQuery(query);
while(rsp.next()){
    int id = rsp.getInt(1);
    double fpis = rsp.getDouble(2);
    double fnis = rsp.getDouble(3);
    prSt.setInt(1, id);
    prSt.setDouble(2, fnis/(fnis+fpis));
    prSt.setInt(3, THIS PART i dont understand)
    prSt.executeUpdate();
}

What should i add so the RANKING column is automatically filled by the rank of the data according to the SCORE column?

DonQuixote
  • 15
  • 5

1 Answers1

0

I think this approach is not beneficial. It will generate ambiguous data for rank. e.g. if we insert the first row with (score 99) the rank will be 1 and after it, we insert the second row with score 100 what is the rank? (according to runtime calculation rant should 1 but we have already 1 so what can we do?). So, its prefer to use it only will select data from the table for showing.

Hopefully, you know the syntax as ( RANK ( ) OVER ( [ partition_by_clause ] order_by_clause ) )

M Danish
  • 480
  • 2
  • 5