是不是这样???select top 3 b.b from a,b where a.a1=b.a or a.a2=b.a2 ... order by b.c
select top 3 b.b from a,b where a.a1=b.a or a.a2=b.a ... order by b.c
不小心又到这里netcoder(朱二) 很有创意,不过加个top 3 也许更能体现....
横排,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,'')
top 3 出来的数据只是纵向的,而且条件也不对阿
按樓主的說法,你要的表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
按樓主的說法,你要的表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
where a.a1=b.a or a.a2=b.a2 ...
order by b.c
where a.a1=b.a or a.a2=b.a ...
order by b.c
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,'')
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
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