将字符串变量附加到排名列值

时间:2017-10-24 15:08:59

标签: java sql

我在这里帮助更新一个表列,其中包含来自计算排名列的值。我可以将字符串变量附加到它们,使得代替像1,2,3,4这样的值...它们将是第1,第2 ,3日,4日.. 我写了这段代码:

//code create computed ranked column
    String sql1 = SELECT COUNT(DISTINCT s2.Total) AS Rank from class1 s1 
    JOIN class1 s2 on (s1.Total<=s2.Total)
    GROUP BY s1.ID order by s1.Name ASC;
    pst = conn.prepareStatement(sql1);
    rs = pst.executeQuery();

    // attaching a string variable to the resultset
        String type = rs.getString(2);
            typ=Integer.parseInt(type);
            String type1 = "";
            if(typ==1){
            type1="st";
          }else if(typ==2){
            type1="nd";
            }else if(typ==3){
            type1="rd";
            }else if(typ>3){
            type1="th";
            }

//updating table column with the resultset
            String sql = "";
            while (rs.next()) { 
            sql = "update class1 set Position='"+rs.getString(2)+type1+"'"+" WHERE ID="+rs.getString(1); 
           pst=conn.prepareStatement(sql);
           pst.execute();

但这样做是为了将第一行的结果重复到所有行..

| NAME |分数1 |分数2 |总计|位置|
-------------------------------------------------- ----------------------
|詹姆斯| 10.0 | 24.0 | 34.0 | 1 |
|吉米| 10.0 | 20.0 | 30.0 | 2ST |
|乔希| 10.0 | 19.0 | 29.0 | 3ST |

我如何让它像

一样工作

| NAME |分数1 |分数2 |总计|位置|
-------------------------------------------------- ----------------------
|詹姆斯| 10.0 | 24.0 | 34.0 | 1 |
|吉米| 10.0 | 20.0 | 30.0 |第二|
|乔希| 10.0 | 19.0 | 29.0 | 3 |

谢谢。

0 个答案:

没有答案