如何解决联表查询记录重复问题:急,马上结题

erh 2003-08-30 12:00:51
输出字段包括父表和子表
...全文
45 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
erh 2003-08-30
  • 打赏
  • 举报
回复
谢谢
txlicenhe 2003-08-30
  • 打赏
  • 举报
回复
不知楼主想要???
lfengxu 2003-08-30
  • 打赏
  • 举报
回复

declare @a varchar(8000),@b int,@c int

select a.so_contract_id,(b.unit*b.price) as total,a.so_contract_date,a.delivery_date, c.prod_type,b.prod_id,0 gr,cast('' as varchar(8000)) value into #aaa
from so_contract a,so_contract_prod b,product c
where a.so_contract_id=b.so_contract_id and b.prod_id=c.prod_id and (a.state=(select max(approver_step) from process_function,approve_process
where process_function.approver_id=approve_process.approver_id and process_function.table_name='so_contract'))
set @c=0
update #aaa set @a=case when @b=so_contract_id then @a else '' end+prod_type+',',
@c=case when @b=so_contract_id then @c else @c+1 end,@b=so_contract_id,gr=@c,value=@a

select max(so_contract_id) as so_contract_id,max(value) result into #bbb from #aaa group by gr
--select * from #bbb
--select * from #aaa
select a.so_contract_id,(select sum(total) from #aaa ) as total,a.so_contract_date,a.delivery_date,a.prod_id,b.result as prod_type
from #aaa a,#bbb b
where a.so_contract_id=b.so_contract_id and a.value=b.result
--select @d=@d+','+ch from #临时表
--select right(@d,len(@d)-1)

drop table #aaa
drop table #bbb

你去是一下吧。前天有人问过大力。我的问题也解决了。应该是你想要得吧!!!
解决了要给分呀

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧