要求从表中找出工资相等的人的名字,不考虑重复??

解决方案 »

  1.   

    你是指什么?给定一个工资,找到工资相等的其他用户名?
    select username from salary where pay = xxx
    就可以
    如果你指所有相同工资的人,可以这样
    select username, pay from salary where pay in (select pay from salary group by pay having count(*) >= 2)
      

  2.   

    谢谢,但是要求的使用java写算法
      

  3.   

    当然是使用SQL语句啦,自己都读到内存的话那要多少内存啊。
    如果你确定数据不大,那也很简单public class Employyee implements Comparable {
      private double salary;
      public int compare(Object obj) {
        return this.salary - ((Employe)obj).salary;
      }
    }public void getPaySame() {
      List allEmployee = getAllEmployee();//读取出所有员工
      java.util.Collections.sort(allEmployee);
      for(int i = 1; i < allEmployee.size(); i++) {
         Employee last = (Employee)allEmployee.get(i - 1);
         Employee current = (Employee)allEmployee.get(i);
         if(last.salary == current.salary)
           System.out.println(last.name + "=" + current.name);
      }
    }