2

I have the following, but I need the answer in percentage and I keep getting 0. I was wondering how to round my answer. Thanks in advance!

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'
4

4 回答 4

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'
于 2013-03-20T07:11:04.590 回答
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

于 2013-03-20T07:31:16.530 回答
0

您还可以将CAST 或 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'

或者

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'
于 2013-03-20T07:33:48.577 回答
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'
于 2013-03-21T06:55:43.953 回答