我试图除以查看医疗实践提供的数据的百分比,但没有结果,每行中只有零。 在此输入图片描述
我尝试将其转换为 BigInt,看看这是否是问题所在。该列的数据类型是tinyint,如果这有帮助的话。
WITH CTE1(Specialty, Total_Instances) AS
(
SELECT
Specialty, COUNT(Severity) AS Total_Instances
FROM
MedMal85
GROUP BY
Specialty
)
SELECT
SUM(Total_Instances) Total_Amount_of_Malpractice_Events
FROM
CTE1;
-- I want to see, the events per category next.
SELECT
Specialty, COUNT(Severity) AS Total_Events
FROM
MedMal85
GROUP BY
Specialty;
SELECT
Specialty, COUNT(CONVERT(float, Severity)) / 158420 Percentage_of_Total_Events
FROM
MedMal85
GROUP BY
Specialty;
也许您必须将列转换为理性数据类型而不是 bigint。如果您使用整数类型,则除法时出现的小数将被删除。所以0。????会变成0
编辑: 如果您使用:
Count(Convert(float, Severity))/158420
您将严重性列的所有条目转换为浮点数,然后计算有多少行。但 COUNT 返回一个整数。您需要切换函数调用,以便 COUNT 的结果转换为浮点数:
Convert(float, Count(Severity)) / 158420