我需要根据癌症的发生情况对病人进行计数。我将共享示例数据集和预期结果,供您参考。
ID Date Inf Cancer
123 05/05/2000 1 0
123 08/07/2001 0 1
123 06/07/2002 1 0
159 01/03/2001 1 1
159 02/08/2002 0 1
618 07/07/2005 0 0
618 05/03/2006 1 0
789 06/06/2000 1 0
789 04/02/2001 0 1
789 03/03/2002 1 0我有两个条件来计算病人的数量。
在癌症(
善意地建议一个代码,以获得结果末尾的病人ID列表。
发布于 2020-02-04 11:41:56
你可以用exists来得到病人。例如,对于第一个条件:
select distinct t.id
from t
where t.inf = 1 and
exists (select 1
from t t2
where t2.id = t.id and
t2.cancer = 1 and
t2.date <= t.date
);对于第二个条件,您也可以做一些类似的事情。
https://stackoverflow.com/questions/60054710
复制相似问题