上面的图片是一个报告输出的屏幕上限,我一直在使用t-SQL表和视图。每列有两个值,第一列是当前数字,然后跟随正斜杠是每周的差值。对于我的大多数报告而言,这些数字看起来很棒,但正如您所看到的那样,Total列似乎有一个完全错误的差异值。
此表是使用以下代码
创建的SELECT
ISNULL(a.[LRPR Biospecimen Consent], 'Missing') AS Consent,
CONVERT(varchar, a.Oppong) + ' / ' + CONVERT(varchar, a.Oppong - ISNULL(b.Oppong, 0)) AS Oppong,
CONVERT(varchar, a.Tousimis) + ' / ' + CONVERT(varchar, a.Tousimis - ISNULL(b.Tousimis, 0)) AS Tousimis,
CONVERT(varchar, a.Willey) + ' / ' + CONVERT(varchar, a.Willey - ISNULL(b.Willey, 0)) AS Willey,
CONVERT(varchar, a.Anderson) + ' / ' + CONVERT(varchar, a.Anderson - ISNULL(b.Anderson, 0)) AS Anderson,
CONVERT(varchar, a.Bacarra) + ' / ' + CONVERT(varchar, a.Bacarra - ISNULL(b.Bacarra, 0)) AS Bacarra,
CONVERT(varchar, a.McMahon) + ' / ' + CONVERT(varchar, a.McMahon - ISNULL(b.McMahon, 0)) AS McMahon
FROM
dbo.vw_RPT_Ourisman_BiospecimenConsentWithProvider_Pivot a
LEFT OUTER JOIN dbo.tbl_vw_RPT_Ourisman_BiospecimenConsentWithProvider_Pivot b
ON ...
此代码的变体(仅更改了路径名)为正斜杠两侧的数字提供了准确的总值。我是新手SQL用户,我似乎无法弄清楚为什么此代码已停止工作
非常感谢任何有用的建议
修改的 下面是用于创建dbo.vw_RPT_Ourisman_BiospecimenConsentWithProvider_Pivot Total值的代码。
With T as ( SELECT [LRPR Biospecimen Consent], [Oppong, Bridget A] AS Oppong, [Tousimis, Eleni] AS Tousimis, [Willey, Shawna] AS Willey, [Anderson, Lyndsay] AS Anderson,
[Bacarra, Minna Manalo] AS Bacarra, [McMahon, Ann] AS McMahon
FROM vw_RPT_Ourisman_BiospecimenConsentWithProvider_List c PIVOT (count([Breast Provider]) FOR [Breast Provider] IN ([Oppong, Bridget A], [Tousimis, Eleni],
[Willey, Shawna], [Anderson, Lyndsay], [Bacarra, Minna Manalo], [McMahon, Ann])) piv
WHERE [LRPR Biospecimen Consent] IS NOT NULL)
SELECT *
FROM T
UNION ALL
SELECT 'Total', SUM(Oppong), SUM(Tousimis), SUM(Willey), SUM(Anderson), SUM(Bacarra), SUM(McMahon)
FROM T