Ignite:SQL查询来计算列的概率

时间:2019-02-26 10:00:52

标签: sql ignite

Gender
-------
Female
Male
Male
Male
Female
Female
Male
Female

在这里我想计算性别列的机率,并尝试以下查询,但是它不起作用。

SELECT (count(*)/(SELECT count(*) from DIABETIC_TOPIC) as probability from DIABETIC_TOPIC group by gender order by gender;

我错过了什么?

1 个答案:

答案 0 :(得分:0)

我会在非分组查询中交叉加入分组查询,并将其划分:

SELECT     gender, cnt_gender / cnt * 100 AS probability
FROM       (SELECT   gender, COUNT(*)
            FROM     diabetic_topic
            GROUP BY gender) a
CROSS JOIN (SELECT COUNT(*) AS cnt
            FROM   diabetic_topic) b