怎么取出 每个诊室(tab_zs) 里面的tab_jhxh 值最小的一行记录

解决方案 »

  1.   

    haoma   zs
    1       1诊室
    2       3诊室
    4       1诊室
    5       2诊室
    3       1诊室查询出来 每个诊室 haoma最小的一行我想要的结果
    haoma  zs
    1      1诊室
    5      2诊室
    2      3诊室
      

  2.   

    select * from tt where not exists(select 1 from tt where a.zs=zs and a.haoma>haoma)
      

  3.   

    参考下贴中的多种方法http://topic.csdn.net/u/20091231/16/2f268740-391e-40f2-a15e-f243b2c925ab.html
    [征集]分组取最大N条记录方法征集,及散分....
      

  4.   

    a 是什么意思 这里就一个表啊  
    select 1 from tt  这个有什么用
      

  5.   

    上面少写了1个A,表别名
    select * from tt A  where not exists(select 1 from tt where a.zs=zs and a.haoma>haoma)
    建议你看看SQL的基础知识
      

  6.   

    select min(haoma) from 表明 group by zs
      

  7.   

    select id,risk from tb a where id in  (select min(id) from tb b where b.risk = a.risk);