如何使用特定列的模式更新该列的空单元格?(使用Java的Sql)
我使用以下代码计算列的模式:如何使用特定列的模式更新该列的空单元格?(使用Java的Sql),java,sql,sql-server,Java,Sql,Sql Server,我使用以下代码计算列的模式: public void CalcCatValMean(String colName , String tableName){ Statement st = null; String sql = null; String mode = null; try{ setConnection(); st = connection.createStatement(ResultSet.TYPE_SCROLL
public void CalcCatValMean(String colName , String tableName){
Statement st = null;
String sql = null;
String mode = null;
try{
setConnection();
st = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
sql = "SELECT " + colName + " , Count(colName) AS Frequency FROM " + tableName + " GROUP BY " + colName + " HAVING Count(colName) >= ALL (SELECT Count(colName) FROM " + tableName + " GROUP BY " + colName + " )";
System.out.println("sql :" + sql);
ResultSet rset = st.executeQuery(sql);
CachedRowSet rowset = new CachedRowSetImpl();
rowset.populate(rset);
int i = 1;
while(rowset.next()) { // check if a result was returned
mode = rowset.getString(i); // get your result
System.out.println("mode is : " + mode);
i++;
}
//Clean-up environment
st.close();
closeConnection();
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
但奇怪的是,它还将“null”计算为一个值&将下一列的输出设为“null”
- 空的
- abc
- 空的
- 空的
- xyz
我要做的是计算该列中除null以外的所有值的模式,然后用计算模式更新该列的null单元格。结果是:
System.out.println(“sql:+sql”)代码>?从何处获得该输出?您没有在Count()
aggregate中将Colname作为参数传递。尝试计数(*)
。还有,我想知道你为什么需要有子句。哦,谢谢,先生,,,实际上这是我愚蠢的错误。。。查询是正确的,但语法是错误的