我使用以下代码计算列的模式:
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”。
我想要做的是计算除null之外的该列的所有值的模式,然后使用计算模式更新该列的空单元格。