postgresql - 为什么我在输入结束时收到错误:语法错误?
问题描述
我不断收到“输入结束时的语法错误”,不知道为什么。
我想要做的是将疾病结果除以总结果,并在疾病部分显示 condition_id。
select disease.condition_id, (disease::float/total::float) as prevalence
from (
select condition_id, count(person_id)
from a.condition
where condition_id=316139
group by condition_id
) as disease
join (
select count(distinct person_id) as total
from a.person
)as total;
有人可以帮我吗?
谢谢!
解决方案
对于您当前的语法,我没有确切的修复方法,但我会将这个查询表述为对整个表进行聚合的连接:
SELECT
COUNT(*) FILTER (WHERE c.condition_id = 316139) /
COUNT(DISTINCT p.person_id) AS prevalence
FROM a.person p
LEFT JOIN a.condition c
ON p.person_id = c.person_id;
推荐阅读
- php - 使用 Codeigniter 创建管理员登录页面
- kubernetes - 在 Openshift 集群上配置 Nginx Ingress Controller 是否可行或正确?
- spring-boot - 为什么父项覆盖子项依赖的版本
- html - 为什么 ":last-child" 选择器对我不起作用?
- r - R不同宽度的冲积地?
- javascript - Javascript“removeEventListener”没有对匿名函数做任何事情,没有简单的方法吗?
- css - 在 Django 中停止缓存
- azure - 无法从 Microsoft Graph API 成功验证访问令牌
- node.js - 我想从一个反应应用程序发布到一个 expressjs api
- karate - 通过空手道框架禁用 Chrome 密码管理器