我有以下内容,但我需要百分比的答案而且我一直都是0.我想知道如何围绕我的答案。提前致谢!
SELECT (COUNT(t1.[ENTRY CODE])/2948) AS 'SecondYearRetention'
FROM
t1
Inner join
t2 ON t1.CLID = t2.CLID
WHERE t1.[ENTRY CODE] = 'FTF' OR t1.[ENTRY CODE] = 'CFTF'
答案 0 :(得分:2)
尝试使用2948.0
代替2948
:
SELECT
(COUNT(t1.[ENTRY CODE]) / 2948.0) AS 'SecondYearRetention'
FROM t1
Inner join t2 ON t1.CLID = t2.CLID
WHERE t1.[ENTRY CODE] = 'FTF' OR t1.[ENTRY CODE] = 'CFTF'
答案 1 :(得分:0)
SELECT ROUND((COUNT(t1.[ENTRY CODE])/2948),3)AS 'SecondYearRetention'
FROM
t1
Inner join
t2 ON t1.CLID = t2.CLID
WHERE t1.[ENTRY CODE] = 'FTF' OR t1.[ENTRY CODE] = 'CFTF'
尝试此操作以获得更多结果http://msdn.microsoft.com/en-us/library/ms175003.aspx
答案 2 :(得分:0)
此外,您可以使用CAST or CONVERT函数和您需要的data_type
SELECT
(CAST(COUNT(t1.[ENTRY CODE]) AS decimal(9,8)) / 2948) AS 'SecondYearRetention'
FROM t1
Inner join t2 ON t1.CLID = t2.CLID
WHERE t1.[ENTRY CODE] = 'FTF' OR t1.[ENTRY CODE] = 'CFTF'
OR
SELECT
(CONVERT(decimal(9,8),COUNT(t1.[ENTRY CODE])) / 2948) AS 'SecondYearRetention'
FROM t1
Inner join t2 ON t1.CLID = t2.CLID
WHERE t1.[ENTRY CODE] = 'FTF' OR t1.[ENTRY CODE] = 'CFTF'
答案 3 :(得分:0)
你可以试试这个:
SELECT ROUND(CAST(COUNT(t1.[ENTRY CODE]) AS FLOAT) / 2948),3) AS 'SecondYearRetention'
FROM
t1
Inner join
t2 ON t1.CLID = t2.CLID
WHERE t1.[ENTRY CODE] = 'FTF' OR t1.[ENTRY CODE] = 'CFTF'