select a.* 
from v_info a join(
select info_id=max(a.info_id) 
from info a join(
select kind_code=1401
union all select 1402
union all select 1403
union all select 1404
union all select 1501
union all select 1904
union all select 1801
union all select 1802
union all select 1804
union all select 1405
union all select 1901
)b on a.kind_code=b.kind_code
group by a.kind_code
)b on a.info_id=b.info_id

解决方案 »

  1.   

    --试试那种效率高一点:select a.* 
    from v_info a join(
    select kind_code=1401
    union all select 1402
    union all select 1403
    union all select 1404
    union all select 1501
    union all select 1904
    union all select 1801
    union all select 1802
    union all select 1804
    union all select 1405
    union all select 1901
    )b on a.kind_code=b.kind_code join(
    select info_id=max(a.info_id) 
    from info
    group by a.kind_code
    )c on a.info_id=b.info_id
      

  2.   

    --如果要提取N条的话,试试这样:
    select a.* 
    from v_info a join(
    select kind_code=1401
    union all select 1402
    union all select 1403
    union all select 1404
    union all select 1501
    union all select 1904
    union all select 1801
    union all select 1802
    union all select 1804
    union all select 1405
    union all select 1901
    )b on a.kind_code=b.kind_code
    where a.info_id in(
    select top n info_id --注意这里的n用具体的数字代替
    from info
    where kind_code=a.kind_code)
      

  3.   

    建索引,可大幅度提交查詢性能
    改為以下試試:
    select * from v_info where info_id = (select max(info_id) from info group by kind_code ) and 
    (kind_code =1401 or kind_code =1402 or ...)
      

  4.   

    提取N条:
    select top n * from  v_info  where ...
      

  5.   

    另外,你的表中,这两个字段要建立索引
    kind_code,info_id
      

  6.   

    在建視圖時就做過濾:create view v_info 
    as 
    select * from 原表
    where  (kind_code =1401 or kind_code =1402 or ...)