如何获得价值与数量不同的人的加权总和
我有一个没有给出预期结果的SQL查询:
CREATE TEMP TABLE tmp_cond_num as
SELECT DISTINCT
a.age
,a.gender
,b.concept_id
,count(distinct a.person_id) as numpat
,round(sum(a.sample_weight)) as w_numpat
FROM tmp_pat a
JOIN analytics.aia_tools.dh_t20_medical_histroy_w_hrc b ON a.person_id = b.person_id
AND a.grp = 1
GROUP BY
a.age
,a.gender
,concept_id
我在这里计算独特的person_id。我需要计算那些独特的人_id的样本权重。现在,W_NUMPAT也正在总结重复的Person_ID。我如何获得独特的person_id的总和?
I have a sql query that is not giving the expected result:
CREATE TEMP TABLE tmp_cond_num as
SELECT DISTINCT
a.age
,a.gender
,b.concept_id
,count(distinct a.person_id) as numpat
,round(sum(a.sample_weight)) as w_numpat
FROM tmp_pat a
JOIN analytics.aia_tools.dh_t20_medical_histroy_w_hrc b ON a.person_id = b.person_id
AND a.grp = 1
GROUP BY
a.age
,a.gender
,concept_id
I am counting distinct person_id here. I need to count the sample weights for those distinct person_id. Right now w_numpat is summing for duplicate person_id too. How do I just get the sum for the distinct person_id?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
需要创建包含不同人结果的子查询。
Need to create subquery that contains distinct person results.