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
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
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)
改為以下試試:
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 ...)
select top n * from v_info where ...
kind_code,info_id
as
select * from 原表
where (kind_code =1401 or kind_code =1402 or ...)