【发布时间】:2016-10-31 11:33:49
【问题描述】:
我试图找到一个选择唯一值的语句。 不像独特/独特,因为这些只是删除重复项。我想获取所有唯一值的列表,只有一个条目。
例如:
值:1、2、3、4、4、5、5、6。
我想得到:1、2、3、6。
编辑:
问题是: 哪些演员(姓名和电影数量)在超过 199 部电影中扮演了具有独特角色名称的角色?
这些是我的桌子:
Table "public.filmparticipation"
Column | Type | Modifiers
----------+---------+-----------
partid | integer |
personid | integer | not null
filmid | integer | not null
parttype | text | not null
Table "public.filmcharacter"
Column | Type | Modifiers
---------------+---------+-----------
partid | integer |
filmcharacter | text |
billingpos | integer |
Table "public.person"
Column | Type | Modifiers
-----------+--------------+-----------
personid | integer |
lastname | text | not null
firstname | text |
gender | character(1) |
这是我迄今为止尝试过的,虽然我什至还没有接近我认为的解决方案:
SELECT p.firstname, COUNT(fp.filmid)
FROM person p INNER JOIN filmparticipation fp
ON p.personid = fp.personid
INNER JOIN filmcharacter fc
ON fc.partid = fp.partid
GROUP BY p.firstname
HAVING COUNT(fc.filmcharacter) = 1;
谢谢。
【问题讨论】:
-
使用 SELECT DISTINCT