Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何制作下表中的相同表格_Sql - Fatal编程技术网

Sql 如何制作下表中的相同表格

Sql 如何制作下表中的相同表格,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

我已经使用下面的代码创建了多个表。 如何使用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 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:我找不到语言来感谢你——行动胜于语言;。在这里,对你的回答表示感谢的适当行动是投票并接受答案。单击向上箭头和答案左侧的复选标记以执行此操作。