列总和 Sql 错误

Sum of column Sql error

我正在忙着创建一个项目,在这个项目中我需要获取列中的疾病数量。我尝试使用 sum 函数并按照教程进行操作,但是它一直告诉我该列不存在。

Connection con=   DriverManager.getConnection( "jdbc:derby://localhost:1527/MiniMed", "nbuser", "nbuser");
          ResultSet rs=con.createStatement().executeQuery("Select sum(Numcount) from Diseasetbl");

           System.out.println("Total Conditions Recorded: "+rs.getString("sum(Numcount)"));

我已经尝试获取条件的总和,但它 returns 它不能使用 varchar...因此它知道我在 table 中确实有列。我无法弄清楚为什么这不起作用,我们将不胜感激,谢谢。 table 称为 Diseasetbl,我想从中获取值的列是一个整数列,称为 Numconditions。

java.sql.SQLException:没有名为:sum(Numcount) 的列。

试试这个,

  • 连接控制= DriverManager.getConnection(jdbc:derby://localhost:1527/MiniMed", "nbuser", "nbuser");

  • ResultSet rs=con.createStatement().executeQuery("Select sum(Numcount) as quantity from Diseasetbl");

  • System.out.println("Total Conditions Recorded: "+rs.getString("quantity"));