基本上,我已将一个计数列除以另一个计数列,以便为我提供一个名为Conversion Rate
的新列。问题是当使用CAST函数显示2个小数位时,它们不应该显示为0.00,它们应该是0.36,0.04,0.56等。如何让它显示正确的小数?
以下是我使用的代码:
CAST (((COUNT (CASE runtime WHEN '1' THEN 1 ELSE NULL END))/(COUNT (*))) AS DECIMAL (10,2))
谢谢
答案 0 :(得分:1)
这样做怎么样?
select cast(avg(case when runtime = '1' then 1.0 else 0 end) as decimal(10, 2))
答案 1 :(得分:0)
不知道出了什么问题。见SqlFiddle
这是我试过的:
COUNT(CASE WHEN runtime = "1" THEN 1 ELSE NULL END) AS cnt1, COUNT(*) AS Cnt2,
CAST(COUNT(CASE WHEN runtime = "1" THEN 1 ELSE NULL END)/COUNT(*) AS DECIMAL(10,2)) AS Result