写一Function
alter function f_hb(@id int)
returns varchar(8000)
as
begin
declare @str varchar(8000)
set @str = ' '
select @str = @str + ',' + cast(stime as varchar) from s where tid = @id
set @str = right(@str , len(@str) - 1)
return(@str)
End
其中 stime 是你需要相加 的字段
tid 是你的外键
s 为你的次表
select t.tid , max(ss) from s,
(select distinct tid ,dbo.f_hb(t.tid) as ss from t) t
where s.tid = t.tid
group by t.tid
t 为主表
1万+

被折叠的 条评论
为什么被折叠?



