2017-07-06 125 views
1

我對devide 2列的查詢工作,我想CASTCONVERT但仍返回0將apperciate你的幫助查詢師返回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

你試圖劃分哪些數字?他們的數據類型是什麼? – Rokuto

回答

-1

我解決了它,事實證明,我剛剛使用了錯誤的數據類型,在我的情況下是decimal我應該想到的REAL這裏是最後一個查詢a.CSP/CAST(b.Total as REAL)

+0

請勿使用REAL。這是不準確的。使用DECIMAL或NUMERIC –