此代码用于查找员工的最高工资,使用java在netbeans中的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
答案 0 :(得分:0)
我很惊讶这个查询返回任何内容。你在寻找的是:
SELECT *
FROM firsttable
WHERE salary = (SELECT MAX(salary) FROM firsttable)
或
SELECT *
FROM firsttable
HAVING salary = MAX(salary)