Sql 如何制作下表中的相同表格
我已经使用下面的代码创建了多个表。 如何使用sql在一个表中包含变量total_childs和tot_0_5Sql 如何制作下表中的相同表格,sql,Sql,我已经使用下面的代码创建了多个表。 如何使用sql在一个表中包含变量total_childs和tot_0_5 proc sql; create table total as select *, count (distinct var_name1) as total_name from data group by var_name2 order by total_name; proc sql; create table total as s
proc sql;
create table total as select *,
count (distinct var_name1) as total_name
from data
group by var_name2
order by total_name;
proc sql;
create table total as select (*),
count (distinct id) as var_name
from data where age='age_category'
group by var_name
order var_name;
您可以使用条件聚合:
select drug,
count(distinct mbr_id) as total_kids,
count(distinct case when agecat = '0-5' then mbr_id end) as tot_0_5
from dt
group by drug
order by total_kids;
你好,戈登,我花了几个小时来做这件事,你做了一秒钟,我找不到语言来感谢你。非常感谢。@Freniks:我找不到语言来感谢你——行动胜于语言;。在这里,对你的回答表示感谢的适当行动是投票并接受答案。单击向上箭头和答案左侧的复选标记以执行此操作。