我有三个表的内容, 分别是:
sitename times
all 108
site2 36
sitename company_id times
all 0005 35
all 0009 63
all 0023 10
site2 0005 35
site2 0023 1
sitename company_id pact_id times
all 0005 0001 35
all 0009 0001 63
all 0023 0002 10
site2 0005 0001 35
site2 0023 0001 1
要求查询的结果能够显示为这个样子
sitename company_id pact_id times
all 108
0005 35
0001 35
0009 63
0001 63
0023 10
0002 10
site2 36
0005 35
0001 35
0023 1
0001 1
不用游标嵌套循环要怎么做呢?恳请高手解答
------解决方案--------------------
没有做过,帮顶
------解决方案--------------------
感觉好奇怪的要求,帮顶!
------解决方案--------------------
学习帮顶
------解决方案--------------------
select 'all ' sitename,108 times into t1 union
select 'site2 ' sitename,36 times
go
select 'all ' sitename, '0005 ' company_id, 35 times into t2 union
select 'all ' sitename, '0009 ' company_id, 63 times union
select 'all ' sitename, '0023 ' company_id, 10 times union
select 'site2 ' sitename, '0005 ' company_id, 35 times union
select 'site2 ' sitename, '0023 ' company_id, 1 times
go
select 'all ' sitename, '0005 ' company_id, '0001 ' pact_id, 35 times into t3 union
select 'all ' sitename, '0009 ' company_id, '0001 ' pact_id, 63 times union
select 'all ' sitename, '0023 ' company_id, '0002 ' pact_id, 10 times union
select 'site2 ' sitename, '0005 ' company_id, '0001 ' pact_id, 35 times union