Select *,(select count(*) from 表 where 人员编号 = a.人员编号 and 住院次数<= a.住院次数) as state from 表 a

解决方案 »

  1.   

    select *,(select count(*) from 表 where 人员编号=tem.人员编号 and 住院次数<=tem.住院次数) state from 表 tem
      

  2.   

    txlicenhe(马可) 兄:
    能解释一下吗.
      

  3.   

    select 编号,住院次数,住院次数 as state from 表 where ((住院次数<3) and 编号=1001) or (编号=1002) union 
    select 编号,住院次数,3 as state from 表 where ((住院次数=5) and 编号=1001)
      

  4.   

    Select *,(select sum(1) from 表 where 人员编号 = a.人员编号 and 住院次数<= a.住院次数) as state from 表 a