错误地返回SQL查询号

时间:2013-09-20 14:57:47

标签: sql-server-2005

我很难过为什么这不会返回正确的值。我有这个问题:

SELECT 
  ClosingMonth,
  CAST(SUM(EstSale10)as DECIMAL (10,2)) as 'EstSale10',
  CAST(SUM(EstSale25)as DECIMAL(10,2)) as 'EstSale25'
FROM(
  SELECT ClosingMonth,
    SUM(EstSaleLessWar) OVER (PARTITION BY ClosingMonth) AS 'EstSale10',
    0.00 AS 'EstSale25'
  FROM dbo.Contracting_SAF
    WHERE OwnerID = '65'
        AND Year = '2013'
        AND ClosingMonth = 'December'
        AND Status != '10'
        AND ConfLevel = 'Not Likely (10%)'
   UNION ALL
   SELECT ClosingMonth,
     0.00 AS 'EstSale10',
     SUM(EstSaleLessWar) OVER (PARTITION BY ClosingMonth) AS 'EstSale25'
   FROM dbo.Contracting_SAF
     WHERE OwnerID = '65'
        AND Year = '2013'
        AND ClosingMonth = 'December'
        AND Status != '10'
        AND ConfLevel = 'Low (25%)') T
GROUP BY T.ClosingMonth

我的结果如下:

December | 0.00 | 29106570.00

问题是在PHP中使用number_format显示这个值是29,106,570.00,当它应该只有2,910,657.00,因为我在下面的这个单一查询中得到:

SELECT SUM(EstSaleLessWar) 
FROM Contracting_SAF
WHERE OwnerID = '65' 
    AND Year = '2013' 
    AND ClosingMonth = 'December' 
   AND ConfLevel = 'Low (25%)'

查询结果:

2910657.00

帮助!!我做错了什么?

0 个答案:

没有答案