【发布时间】:2021-05-05 03:07:33
【问题描述】:
我想按州统计在美国进行的审判次数。我需要的信息来自 nct_id、state 和 country 列。我在 Macbook Pro 上的 pgAdmin 中。下面是一个小样本:
nct_id state country
NCT04832854 Illinois United States
NCT04832851 Michigan United States
NCT04832802 California United States
NCT04832813 Naples Italy
NCT04832813 Illinois United States
我想按州对 nct_id 进行分组,但前提是该国家/地区是“美国”。到目前为止我有这个。我收到一条错误消息:ERROR: syntax error at or near "AS" LINE 3: COUNT(nct_id) AS Count_Trials。我不确定这里的语法错误是什么。
SELECT nct_id, state
FROM facilities
COUNT(nct_id) AS Count_Trials
GROUP BY state
HAVING Country = 'United States'
我希望输出如下所示:
state Count_Trials
Illinois 2
Michigan 1
California 1
【问题讨论】:
标签: sql postgresql