1
4

2 回答 2

0

答案是“是”。我发现跟踪您的表格和列有点困难。假设提供者的集合不同,然后对没有电话号码的提供者进行计数,然后将其与您加入第二个表的计数结合起来。

查询看起来像:

select PROV_PHONE, count(distinct prv_id) as uni_prv, count(distinct pt_id) as uni_pt
from a
where PRV_SPECIAL_HANDLING='N'
group by prov_phone
union all
select PROV_PHONE, count(distinct prv_id) as uni_prv, count(distinct pt_id) as uni_pt
from a join
     b
     on a.prv_id = b.prv_id
where PRV_SPECIAL_HANDLING='Y'
group by prov_phone

如果有重叠,那么您需要在组之前通过以下方式进行联合:

select PROV_PHONE, count(distinct prv_id) as uni_prv, count(distinct pt_id) as uni_pt
from ((select PROV_PHONE, prv_id, pt_id
       from a
       where PRV_SPECIAL_HANDLING='N'
       group by prov_phone
      ) union all
      (select PROV_PHONE, b.prv_id, b.pt_id
       from a join
            b
            on a.prv_id = b.prv_id
       where PRV_SPECIAL_HANDLING='Y'
      )
     ) t
 group by prov_phone

count(unique)count(distinct). 我很确定 SAS 支持后者并且它是标准 SQL。

于 2012-10-25T19:25:53.630 回答
0

我认为你可以使用一个ifc语句来实现你所需要的技术,如下所示:

select count(distinct ifc(sex='M',name,'DUMMYVALUE')) -1 as number_of_distinct_male_names
from my sashelp.class

您需要减去 -1,因为“DUMMYVALUE”会将 1 添加到唯一男性姓名列表中。

在你的情况下,它会有点复杂,因为你有两个条件要满足,所以你需要嵌套ifc语句:

select count(distinct   
             ifc(if_my_condition1_is_met,
                 unique_value,
                 ifc(if_my_condition2_is_met, 
                     alternate_unique_value, 
                     'DUMMY_VALUE')
                ) -1 as number_of_conditional_unique_values
from my table
于 2012-10-25T19:54:37.263 回答