select * from detail A where C = (select min(C) from detail where A = A.A and B = B.B)
1,建自定义函数 create function getstr(@a int, @b int) returns Nvarchar(4000) as begin declare @str Nvarchar(2000) set @str=N'' select @str=@str+rtrim(C)+N' or ' from detail where A = @a and B = @b if @str<>N'' set @str=left(@str,len(@str)-4) return @str endGO2, select A, B, dbo. getstr(A, B) as C from master
where C = (select min(C) from detail where A = A.A and B = B.B)
create function getstr(@a int, @b int)
returns Nvarchar(4000)
as
begin
declare @str Nvarchar(2000)
set @str=N''
select @str=@str+rtrim(C)+N' or ' from detail
where A = @a and B = @b
if @str<>N''
set @str=left(@str,len(@str)-4)
return @str
endGO2,
select A, B, dbo. getstr(A, B) as C from master