表1:书虫数据库的模式。主键带下划线。有一些外键引用将表连接在一起;你可以使用这些与自然连接。带有DISTINCT语句的SQL SUM聚合
Author(aid, alastname, afirstname, acountry, aborn, adied).
Book(bid, btitle, pid, bdate, bpages, bprice).
City(cid, cname, cstate, ccountry).
Publisher(pid, pname).
Author_Book(aid, bid).
Publisher_City(pid, cid).
这个问题让我有点困惑,任何帮助都非常感谢。
查找每个国家/地区的作者数量。
到目前为止,我已经尝试
SELECT
SUM(DISTINCT acountry) AS total,
COUNT(DISTINCT acountry)AS N
FROM Author;
并得到:
ERROR: function sum(character varying) does not exist LINE 1: select sum(distinct acountry) as total, count(distinct acoun...
提示:无功能的指定名称和参数类型相匹配。您可能需要添加显式类型转换。
您不能“求和”字符串。你认为“Arthur”和“Zaphod”的“总和”是什么?你想解决什么问题? – 2015-02-24 07:24:35
好的,现在我明白了,谢谢。如何使用count语句呢? @a_horse_with_no_name。 – 2015-02-24 07:27:10
您需要使用具有集合函数的'group' – 2015-02-24 07:28:44