【发布时间】:2021-04-20 13:22:16
【问题描述】:
使用 PostgreSQL:我有一个名为“people”的表,有 4 列: id、user_id、date_id 和 status(可以有两个值:“showed”“signup”)
我希望通过选择查询显示 3 列:
SELECT date_id, count(DISTINCT p.user_id) as people_attending, count(p.id) as people_registered
FROM people p
where (p.status::TEXT = 'showed') + MISSING PART HERE??
GROUP BY date_id
ORDER BY "date_id" ASC
希望得到这个:
date_id || people_attending || people_registered
12 || 100 || 230
34 || 10 || 12
基本上,我试图选择一列 (people_attending),其中 p.status = "showed",然后选择第三列 (people_registered),其中 p.status = 所有案例。我的前两列对上面的查询很好,但是,第三列是个问题。
我很难找到解决方案,阅读 Selecting same column twice from a single table but with different conditions 并尝试进行自我加入。
感谢您的帮助, 嗯。
【问题讨论】:
标签: postgresql inner-join