问个问题
select employee_id,max(rem4) from Evaluate where rem1=1 group by employee_id
请问,我还想在select这边加一个字段如test_no,这个字段也是这个表里的,但是报错,请问还有什么方法吗?注:employee_id是用户名
    rem4是时间

解决方案 »

  1.   

    select employee_id,test_no,max(rem4) from Evaluate where rem1=1 group by employee_id,test_no
      

  2.   

    test_no
    也要放到group by里
    要么 聚合这个列test_no
      

  3.   

    select employee_id,max(test_no) as test_no,max(rem4) from Evaluate where rem1=1 group by employee_id,test_no
      

  4.   

    去掉group by 的組
    select employee_id,max(test_no) as test_no,max(rem4) from Evaluate where rem1=1 group by employee_id
      

  5.   

    我试了,如果加上test_no,max()就起不到作用了
      

  6.   

    test_no 是这个表中另一个列,程序中有需要它的,所以我只想在不影响查询结果的情况下,把另一列也查询出来
      

  7.   


    max(test_no) as test_no--在select 處
      

  8.   

    ---try
    select * from Evaluate t where  rem4=(select max(rem4) from Evaluate where employee_id=t.employee_id)
      

  9.   

    select * from Evaluate t where rem4=(select max(rem4) from Evaluate where employee_id=t.employee_id) and rem1=1 
      

  10.   

    select
     employee_id,test_no,rem4 
    from
     Evaluate t 
    where
     rem4=(select max(rem4) from Evaluate where employee_id=t.employee_id) 
    and
     rem1=1 
      

  11.   

    9楼,你说的那个max(test_no) as test_no--在select 處和我的意思不一样
    max(里面是时间,接近现在,就出来) test_no 是测试号
      

  12.   

    select employee_id,test_no,rem4
     from evaluate a 
     where rem1=1
     and not exists(select 1 from evaluate where rem1=1 and employee_id=a.employee_id and rem4>a.rem4)
      

  13.   

    select employee_id,
    max(rem4) from Evaluate where rem1=1 group by employee_id改為
    select * from Evaluate as a where rem1=1 not exists(select 1 from Evaluate  where rem1=a.rem1 and rem4>a.rem4)
      

  14.   

    少打了一下條件員工列
    select * from Evaluate as a where rem1=1 not exists(select 1 from Evaluate  where rem1=a.rem1 and employee_id=a.employee_id and rem4>a.rem4)