select max(ioid), accname from table group by accname

解决方案 »

  1.   

    select * from tab where ioid+accname in (select max(ioid)+accname from tab)
      

  2.   

    select accnam,max(ioid) from table
    group by accname
      

  3.   

    select * from tab where ioid+accname in (select max(ioid)+accname from tab group by accname)
      

  4.   

    select ioid top1 from table
    group by accname
    order by ioid desc
      

  5.   

    select max(ioid) as ioid,accname from table
    group by accname
      

  6.   

    希希的: 列 'tb_acc_io.io_id' 在选择列表中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句中。 alexwoowf(吴) 的:  将 varchar 值 'epson ' 转换为数据类型为 int 的列时发生语法错误。 《ioid 是int 类型的,accname是char类型的》
    怎么解决呢?
    谢谢
      

  7.   

    难道这个都不好使吗??
    select max(ioid) as ioid,accname from table
    group by accname
      

  8.   

    leimin 的 :如过还要选择其他列如io_accnum的话,也报列 'tb_acc_io.io_outnum' 在选择列表中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句中。
      

  9.   

    yoki(小马哥)   :这个就不能选择其他字段。和我楼上的回复一样
    该怎样呢?
      

  10.   

    you should do it as follows:
    select ioid, accname, io_accnum from tb_acc_io where ioid in 
    (select max(ioid) from tb_acc_io group by accname) order by ioid
      

  11.   

    up is right!or you can try below:
    select a.ioid,a.accname,a.io_accnum from tb_acc_io as a
    right outer join  
    (select max(ioid)  as ioid1 from tb_acc_io group by accname)b
    on a.ioid=b.ioid1