尝试从 MySQL 获取特定月份和计数值到变量中

Trying to get specific month and count value from MySQL into variables

我运行在 MySQL 中使用此脚本来检索按特定类型和月份分组的约会计数:

SELECT 类型,月份(开始),COUNT(类型)来自约会 按类型分组,月份(开始);

这为我提供了这个 table: [1]: https://i.stack.imgur.com/sRJwx.png

太棒了!现在我的问题是尝试将数据放入变量中:

String sql = "SELECT `Type`, month(`Start`), COUNT(Type) FROM appointments " +
                "GROUP BY `Type`, month(`Start`)";

        try(Statement s = DatabaseConnection.getConnection().createStatement();
        ResultSet rs = s.executeQuery(sql)) {
            while(rs.next()) {
                String typeKey = rs.getString("Type");
                int monthValue = rs.getInt("month(Start)");
                int count = rs.getInt("COUNT(Type)");

当我 运行 这样做时,我得到一个 SQLException,说找不到列“month(Type)”。我已经尝试使用列名称“Start”并尝试仅使用“month”并收到相同的 SQLException(我知道,这是一种愚蠢的故障排除,但值得一试)。我四处寻找一些解决方案,但我做不到。

这是一个学校项目,所以我只能使用 JDBC 和 Java 特定的驱动程序。如果有人能指出正确的方向,我将不胜感激。

尝试使用 as

重命名列
sql = "SELECT `Type` as type ,
               month(`Start`) as mstart,
               COUNT(Type) as ctype
               FROM appointments " +
               "GROUP BY `Type`, month(`Start`)";