0

此代码用于查找员工的最高工资,使用 netbeans 中的 java 存储在 phpmyadmin 数据库中的数据:

case 5:{//start of max salary 5
    RS = st.executeQuery("select * from firsttable  where having max(salary)");

    System.out.println("the employee with max salary: ");
    while (RS.next())
    {  //start while loop
        //retrieve data

       String []data = {RS.getString("ID"),
                        RS.getString("firstName"),
                        RS.getString("lastName"),
                        RS.getString("birthDate"),
                        RS.getString("salary"),
                        RS.getString("lastLogin")};

        {//start print data
        System.out.println("ID: "+data[0]);
        //System.out.println("ID int: "+RS.getInt("ID"));
        System.out.println("firstName: "+data[1]);
        System.out.println("lastName: "+data[2]);
        System.out.println("birthDate: "+data[3]);
        System.out.println("salary: "+data[4]);
        System.out.println("lastLogin: "+data[5]);
        }//end print data

    }//end while loop

    break;
}//end of max salary 5
4

1 回答 1

0

我很惊讶这个查询会返回任何东西。您正在寻找的是:

SELECT *
FROM firsttable
WHERE salary = (SELECT MAX(salary) FROM firsttable)

或者

SELECT *
FROM firsttable
HAVING salary = MAX(salary)
于 2013-06-19T08:57:20.290 回答