select a.*,b.*
from a,b
where a.PRG0200 =b.PRG0200 and
a.主键=(select top 1 主键 from A b where b.PRG0200 =a.PRG0200 )
from a,b
where a.PRG0200 =b.PRG0200 and
a.主键=(select top 1 主键 from A b where b.PRG0200 =a.PRG0200 )
from a,b
where a.PRG0200 =b.PRG0200 and
a.主键=(select top 1 主键 from A b where b.PRG0200 =a.PRG0200 )
select a.*,b.*
from a,b
where a.PRG0200 =b.PRG0200 and
a.主键=(select 主键 from A b where b.PRG0200 =a.PRG0200 )
---order by ....
32
32
32
33
33
33B30
31
32
33我选择的结果是多条
但A表的ID是不重复的 重复时 选第1条
from #t a,b
where a.PRG0200 =b.PRG0200 and
a.idd=(select top 1 idd from #t b where b.PRG0200 =a.PRG0200 order by b.idd)
不行
运行这条语句后,给重复的编号加上一个不同的标识,查询的时候用来确定相同PRG0200 号的第一条
你没有试我写的语句吧
如果没有的话,试试下面的语句。我在自己机器上实现了
declare @Series varchar(10)
declare B_cursor cursor forselect distinct PRG0200 from b
order by PRG0200
open PRG0200
fetch next from B_cursor into @Series
while @@fetch_status=0
begin
select top 1 PRG0200 from a where PRG0200=@Series
fetch next from B_cursor into @Series
end
CLOSE B_cursor
DEALLOCATE B_cursor建议设关键字,这样速度可以快很多!!