我需要一些帮助。TSQL - 将两个虚拟表与左外部连接相结合
我有一个名为@combine
下面表格是它的结果
我有表@monthofyear和绘制表格我想(见图片2) enter image description here
我想做一个查询,会给我这个DRAW表,所以我可以在SSRS中绘制图表
我红很多论坛说,我必须做表之间的LEFT OUTER JOIN来激活DRAW表。
这里是我的代码:
select ss.Phil
,ss.amounttype
,m.months
,ss.allmount
from @monthofyear as m
left outer join (
select c.phil
,c.amounttype
,c.month_name
,sum(COALESCE(c.amount, 0)) as allmount
from @combine as c
group by phil
,amounttype
,month_name
) ss on (m.months = ss.month_name)
where ss.phil = 'F-14-0023'
group by ss.phil
,ss.amounttype
,m.months
,ss.allmount
它不给我绘制表格布局。有人可以帮帮我吗?
电流输出:
Phil amounttype months allmount
F-14-0023 ACTUAL February 594.46
F-14-0023 ACTUAL January 7019.23
F-14-0023 BUDGET April 1340.00
F-14-0023 BUDGET December 282500.00
F-14-0023 BUDGET February 1340.00
F-14-0023 BUDGET January 1340.00
F-14-0023 BUDGET July -282647.00
F-14-0023 BUDGET March 1340.00
F-14-0023 FORECAST March 1303.36
所需的输出
Phil amounttype months allmount
F-14-23 ACTUAL Feb 594.46
F-14-23 ACTUAL Jan 7019.23
F-14-23 ACTUAL Mar 0
F-14-23 ACTUAL Apr 0
F-14-23 ACTUAL May 0
F-14-23 ACTUAL June 0
F-14-23 ACTUAL July 0
(until December)
F-14-23 BUDGET Apr 1340
F-14-23 BUDGET Dec 282500
F-14-23 BUDGET Feb 1340
F-14-23 BUDGET Jan 1340
F-14-23 BUDGET July -282647
F-14-23 BUDGET Mar 1340
F-14-23 BUDGET Jan 0
F-14-23 BUDGET May 0
F-14-23 BUDGET June 0
(all other months)
F-14-23 FORECAST Mar 130.36
(all other months)
**输出,ALAN代码****
Phil amounttype monthsname AllAmount
Phil amounttype monthsname AllAmount
NULL NULL August 0
NULL NULL June 0
NULL NULL May 0
NULL NULL November 0
NULL NULL October 0
NULL NULL September 0
F-14-0023 BUDGET April 1340
F-14-0023 BUDGET December 282500
F-14-0023 BUDGET February 1340
F-14-0023 BUDGET January 1340
F-14-0023 BUDGET July -282647
F-14-0023 BUDGET March 1340
代码在这里
以文本形式发布表格和数据[阅读此](http://meta.stackoverflow.com/questions/285551/why-may-i-not-upload-images-of-code-on-so-when - 问题/ 285557#285557) –
你的意思是'不给我DRAW图表布局.'?问题是什么? –
我们无法在评论中阅读数据。编辑你的问题显示,当前和欲望输出...并解释什么是错的 –