how to calculate prevalence using sql code

前端 未结 3 494
伪装坚强ぢ
伪装坚强ぢ 2021-01-28 04:36

I am trying to calculate prevalence in sql. kind of stuck in writing the code. I want to make automative code.

I have check that I have 1453477 of sample size and numbe

3条回答
  •  囚心锁ツ
    2021-01-28 05:08

    In your current query you count the number of rows in the disease table, once using the column condition_id, once using the column person_id. But the number of rows is the same - this is why you get 1 as a result.

    I think you need to find the number of different values for these columns. This can be done using count distinct:

    select (COUNT(DISTINCT condition_id)/COUNT(DISTINCT person_id)) as prevalence
    from disease
    where condition_id=12345;
    

提交回复
热议问题