在access2003中,将同一字段的最后6个不同记录合并在一起

来源:百度知道 编辑:UC知道 时间:2024/05/06 15:25:03
例如:
id neirong
1 我
2 爱
3 中
4 华
5 大
6 家

合并为查询: 家,大,华,中,爱,我

是按照ID排序的最后六个记录的NEIRONG字段,ID可以任意值,可以不连续。
sql server当中测试过,请自已在ACCESS中测试
select
a.neirong+','+
b.neirong+','+
c.neirong+','+
d.neirong+','+
e.neirong+','+
f.neirong
from
tablename a,
tablename b,
tablename c,
tablename d,
tablename e,
tablename f
as fieldname
where
a.id=(select max(id) from tablename) and
b.id=(select max(id) from tablename b1 where b1.id<a.id) and
c.id=(select max(id) from tablename c1 where b1.id<b.id) and
d.id=(select max(id) from tablename d1 where b1.id<c.id) and
e.id=(select max(id) from tablename e1 where b1.id<d.id) and
f.id=(select max(id) from tablename f1 where b1.id<e.id)