如何使用 jdbc 计算某个值在表中出现的次数?表中的记录有 200 个可能的值和 4 列。
最佳答案
可能是
Select count(*) from table where item = 'value';
如果您想计算所有 200 个值,那么您可以尝试:
select item,count(*) from table group by item;
<小时/>
演示代码:--
try {
java.sql.Statement s = conn.createStatement();
java.sql.ResultSet r = s.executeQuery("select item,count(*) from table group by item;");
while (r.next()) {
System.out.println(r.getString(1) + " "
+ r.getString(2));
}
} catch (Exception e) {
System.out.println(e);
System.exit(0);
}
关于java - 计算数据库中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5549236/