按樓主的說法,你要的表b中的b字段與表a沒有關系,而你要的又是三個紀錄橫向的資料,那它是個自連接應該這樣寫:
select top 1 a.b,b.b,c.b from (select top 3 b from 表b order by c asc) a join (select top 3 b from 表b order by c asc) b
on a.b<>b.b join (select top 3 b from 表b order by c asc) c on b.b<>c.b and a.b<>c.b
按樓主的說法,你要的表b中的b字段與表a沒有關系,而你要的又是三個紀錄橫向的資料,那它是個自連接應該這樣寫:
select top 1 a.b,b.b,c.b from (select top 3 b from 表b order by c asc) a join (select top 3 b from 表b order by c asc)
on a.b<>b.b join (select top 3 b from 表b order by c asc) c on b.b<>c.b and a.b<>c.b
declare @s varchar(1000)
set @s=''
select @s=@s+','+b.b from (select top 3 b.b from a,b
where a.a1=b.a or a.a2=b.a ...
order by b.c) b
print stuff(@s,1,1,'')