我试图找到一个语句来选择唯一值。 不像独特/独特,导致这些只是删除重复。我想获得所有唯一值的列表,只有一个条目。SQL找到唯一值
例如:
值: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 – user1929959