Вы должны использовать условие HAVING
для проверки условия вместо условия where и дополнительно LISTAGG
может использоваться для отображения названий фильмов.
CREATE OR REPLACE TYPE actortype IS VARRAY(5) OF VARCHAR2(20);
/
create table movie ( id integer , title VARCHAR2(100), actors actortype );
INSERT INTO movie (
id,
title,
actors
) VALUES (
1,
'The Shawshank Redemption',
actortype('Morgan Freeman','Tim Robbins','Bob Gunton')
);
INSERT INTO movie (
id,
title,
actors
) VALUES (
1,
'The Dark Knight',
actortype('Morgan Freeman','Christian Bale','Heath Ledger')
);
Запрос
SELECT a.column_value as Actor,
COUNT(*) as num_of_movies,
LISTAGG( m.title, ',') WITHIN GROUP ( ORDER BY id ) as movies
FROM movie m,
TABLE ( m.actors ) a
GROUP BY a.column_value
HAVING COUNT(*) > 1;
ACTOR NUM_OF_MOVIES MOVIES
------------ ------------- -------
Morgan Freeman 2 The Dark Knight,The Shawshank Redemption