查询除法返回0

时间:2017-07-06 07:40:01

标签: sql sql-server

我正在处理一个包含2列的查询,我尝试了CASTCONVERT,但仍然返回0.请提供帮助

SELECT a.Disposition,a.[Disposition Reason Breakdown],a.CSP,b.Total FROM
(
SELECT a.[Disposition],a.[Disposition Reason Breakdown],a.[CSP] FROM
(
SELECT [Disposition],[Disposition Reason Breakdown],COUNT(*) as CSP FROM [dbo].[Disposition]
WHERE [Disposition] <> 'Interested'
GROUP BY [Disposition],[Disposition Reason Breakdown]
) a
)a
INNER JOIN
(
SELECT a.Disposition,SUM(a.CSP) as Total FROM 
(
SELECT [Disposition],[Disposition Reason Breakdown],COUNT(*) as CSP FROM [dbo].[Disposition]
WHERE [Disposition] <> 'Interested'
GROUP BY [Disposition],[Disposition Reason Breakdown]
)a
GROUP BY a.Disposition
)b ON a.Disposition = b.Disposition

我正在使用sql

1 个答案:

答案 0 :(得分:-1)

我解决了,事实证明我刚刚使用了错误的数据类型,在我的情况下是decimal我应该想到REAL这里是最终查询a.CSP/CAST(b.Total as REAL) < / p>